Servomotor [Help]
This is the first time I use Basic Stamp; but I have knowledge in other programming languages.
Well; what I'm trying to do is simply rotate the Servomotor for 15 seconds, Pause for 5 Seconds, then I need to rotate it in reverse for 10 seconds.
Can I get some help here?
Cheers. :cool:
Well; what I'm trying to do is simply rotate the Servomotor for 15 seconds, Pause for 5 Seconds, then I need to rotate it in reverse for 10 seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
i VAR Word 'This is our counter'
i = 0 'Start it off at 0'
DO
i = i + 1 'Every time it loops add 1 to the counter'
IF i = 2 THEN 'If our counter reaches 2 then it ends the program'
GOTO finish
ENDIF
FOR i = 1 TO 1
PULSOUT 14, 250 'Rotate"
PAUSE 5000 'Pause for 5 seconds'
PULSOUT 14, 1250 'Rotate in reverse"
PAUSE 1000
NEXT
LOOP
finish:
END
That is what I came up with; however, I'm not sure if it's going to work or not yet; and I couldn't figure out how to work with the PULSOUT command that well yet as well as figure out how to make it rotate for a certain duration/direction.Can I get some help here?
Cheers. :cool:
Comments
Forward_15_sec: FOR i = 1 to 750 PULSOUT 14, 250 Pause 19 ' approx 1 millisecond is used in the FOR...NEXT loop and sending the pulse (PAUSE 20 is typically used for simplicity) NEXT RETURN
Thank you for clarifying!
How about rotating in reverse though?
Would this work:
' {$STAMP BS2} ' {$PBASIC 2.5} i VAR Word DO Forward_15_sec: FOR i = 1 TO 750 PULSOUT 14, 250 PAUSE 20 NEXT PAUSE 5000 Backward_10_sec: FOR i = 1 TO 500 PULSOUT 14, 1250 PAUSE 20 NEXT LOOP END
Thank you for all your help!
I appreciate it.
Now how would this work if I were to try to Rotate "2" Servomotors at the same time?
If they both need to go the same direction at the same time and speed, you'd just add the second servo on the same output pin
If NOT, you could add a second PULSOUT for the second servo inside the loops. Keep in mind, the second PULSOUT takes time to execute, so you'll need to adjust your PAUSE time to compensate, correcting your freq back to 50Hz.
Thanks; I think that all I need to do for now is run them at the same time and speed.
Thank you all for your help.
That is correct; but the problem here has been solved.
Thank you anyway.