three questions on BS2
First, my project is to control a·lamp level depending on the light in the room using light sensor wirelessly
so on the receiving part i use BS2 and get the transmited signal using wireless receiver then take an output
to the lamp
this is the code of the receiver
'{$STAMP BS2}
' {$PBASIC 2.5}
datas VAR Byte
i VAR Byte
check:
SERIN 7, 16780, [noparse][[/noparse]WAIT("*!"), DEC2 datas]
PAUSE 300
DEBUG DEC2 datas, CR
IF datas = 1 THEN one
IF datas = 2 THEN two
IF datas = 3 THEN three
IF datas = 4 THEN four
IF datas => 5 THEN five
one:
DEBUG "Level 1", CR
FOR i = 0 TO 5
PWM 4,255,255
NEXT
GOTO check
two:
DEBUG "Level 2", CR
FOR i = 0 TO 5
PWM 4,191,255
NEXT
GOTO check
three:
DEBUG "Level 3", CR
FOR i = 0 TO 5
PWM 4,127,255
NEXT
GOTO check
four:
DEBUG "Level 4", CR
FOR i = 0 TO 5
PWM 4,63,255
NEXT
GOTO check
five:
DEBUG "Level 5", CR
FOR i = 0 TO 5
PWM 4,0,255
NEXT
GOTO check
but i have three problems:
1-the BS2 can't switch on a 2.5V lamp but it do with LED , is because the output current is very small (20mA)??? if it is what is the solution??
2-the LED is blinking··how can i let it work continuesly (because of the FOR loop)??
3-how to let the lamp work continuesly until the level is changed
·i already use voltage·amplifier but make no difference
so on the receiving part i use BS2 and get the transmited signal using wireless receiver then take an output
to the lamp
this is the code of the receiver
'{$STAMP BS2}
' {$PBASIC 2.5}
datas VAR Byte
i VAR Byte
check:
SERIN 7, 16780, [noparse][[/noparse]WAIT("*!"), DEC2 datas]
PAUSE 300
DEBUG DEC2 datas, CR
IF datas = 1 THEN one
IF datas = 2 THEN two
IF datas = 3 THEN three
IF datas = 4 THEN four
IF datas => 5 THEN five
one:
DEBUG "Level 1", CR
FOR i = 0 TO 5
PWM 4,255,255
NEXT
GOTO check
two:
DEBUG "Level 2", CR
FOR i = 0 TO 5
PWM 4,191,255
NEXT
GOTO check
three:
DEBUG "Level 3", CR
FOR i = 0 TO 5
PWM 4,127,255
NEXT
GOTO check
four:
DEBUG "Level 4", CR
FOR i = 0 TO 5
PWM 4,63,255
NEXT
GOTO check
five:
DEBUG "Level 5", CR
FOR i = 0 TO 5
PWM 4,0,255
NEXT
GOTO check
but i have three problems:
1-the BS2 can't switch on a 2.5V lamp but it do with LED , is because the output current is very small (20mA)??? if it is what is the solution??
2-the LED is blinking··how can i let it work continuesly (because of the FOR loop)??
3-how to let the lamp work continuesly until the level is changed
·i already use voltage·amplifier but make no difference
Comments
It provides material on driving larger loads and how to control a device at varying levels continually using a small fan.
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
Here's a bit of code that might help you out as well. Whenever you see a series of routines that are almost alike, it is often possible to shrink things a bit.
'{$STAMP BS2}
' {$PBASIC 2.5}
datas VAR Byte
i VAR Byte
PWMval var byte
check:
SERIN 7, 16780, [noparse][[/noparse]WAIT("*!"), DEC2 datas]
PAUSE 300
DEBUG DEC2 datas, CR
if datas > 5 then
datas=5
PWMval=0
else
PWMval=255-((datas-1)*63)
endif
DEBUG "Level ",dec datas, CR
FOR i = 0 TO 5
PWM 4,PWMval,255
NEXT
GOTO check
I haven't tested this but I think it's good to go.
Lee