push button programming question on BS2
Hi,
I'm new to this. I went through the What's... book and went through the help index in the software. I can't seem to figure this out.
I want to push the button on the homework board and after I let go I want a pause for a few seconds, then turn on the continuous servo for few seconds then stop.
Here is the code, but it doesn't work. Is there any place I can look for sample programs?
Thanks, Bob
' {$STAMP BS2}
' {$PBASIC 2.5}
duration VAR Word
duration = 650
DO
begin:
IF IN3 = 1 THEN
PAUSE UNTIL IN3=0
ENDIF
IF IN3 = 0
THEN PULSOUT 14, duration
PAUSE 10
ENDIF
LOOP
I'm new to this. I went through the What's... book and went through the help index in the software. I can't seem to figure this out.
I want to push the button on the homework board and after I let go I want a pause for a few seconds, then turn on the continuous servo for few seconds then stop.
Here is the code, but it doesn't work. Is there any place I can look for sample programs?
Thanks, Bob
' {$STAMP BS2}
' {$PBASIC 2.5}
duration VAR Word
duration = 650
DO
begin:
IF IN3 = 1 THEN
PAUSE UNTIL IN3=0
ENDIF
IF IN3 = 0
THEN PULSOUT 14, duration
PAUSE 10
ENDIF
LOOP
Comments
You've got the right idea. Partly, you didn't make your program do what you said it should do:
1) Wait for the pushbutton to be pressed (look at the DO / LOOP / UNTIL statement)
2) Wait for the pushbutton to be released (another DO / LOOP)
3) Turn on the servo for a few seconds. This involves sending out a pulse every 20ms (better than 10ms). Look at the FOR / NEXT statement.
4) Stop
Build your program a step at a time and insert DEBUG statements to follow its progress. Make sure it compiles at each step.
Bob