Reversing Servo Timing Pg 84
ChuckThomas
Posts: 4
Hello,
Please educate me.
I am runing the program for Boebot page 84. I selected 11 seconds as my time value. Formula states to divide
selected time by .024 11 / .024 = 458.
Problem when "counter" variable exceeds 255 the "counter" varible·resets back to one and causes an endless loop.
Here is the program:
' Robotics with the Boe-Bot - BothServosThreeSeconds.bs2· Page 84
' Run both servos in opposite directions for three seconds, then reverse
' the direction of both servos and run another three seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG"Program Running!"
counter VAR Byte
FOR counter = 1 TO 255
DEBUG "First loop"
DEBUG ? counter
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
NEXT
PAUSE 500
FOR counter = 1 TO 256
DEBUG "Second loop"
DEBUG ? counter
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20
NEXT
END
Thank you,
Charles Thomas
Please educate me.
I am runing the program for Boebot page 84. I selected 11 seconds as my time value. Formula states to divide
selected time by .024 11 / .024 = 458.
Problem when "counter" variable exceeds 255 the "counter" varible·resets back to one and causes an endless loop.
Here is the program:
' Robotics with the Boe-Bot - BothServosThreeSeconds.bs2· Page 84
' Run both servos in opposite directions for three seconds, then reverse
' the direction of both servos and run another three seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG"Program Running!"
counter VAR Byte
FOR counter = 1 TO 255
DEBUG "First loop"
DEBUG ? counter
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
NEXT
PAUSE 500
FOR counter = 1 TO 256
DEBUG "Second loop"
DEBUG ? counter
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20
NEXT
END
Thank you,
Charles Thomas
Comments
To fix the bug you need to declare the counter variable like:
counter VAR word
Chuck Thomas