Interactives
08-11-2005, 12:00 AM
·Ok, so right now I'm working on making a switch of sorts, that is actually an arrow. The shaft of the arrow has a magnet on it, and positioned around the shaft are ten hall effect sensors. I've written some code to move a servo into position, based on what direction the arrow is pointing. But the code I've written is based on If.. then directives soo... it works the way I have it now, but I thought that servos had to have constant pulses sent to them in order to hold position. If my code is saying "the arrow is pointing left", then is the signal only being sent to the servo for the duration of the parameters of the "IF- THEN" condition? I'll attach my code, I'm just worried that I'm gonna kill another servo. Thankx!!!··
'{$STAMP BS2}
'{$PBASIC 2.5}
' servo control
DEBUG "ready",CR
one VAR Bit············ 'state of the hall effect sensor no. 1
two VAR Bit············ 'state of the hall effect sensor no. 1
three VAR Bit·········· 'state of the hall effect sensor no. 1
'=============================
counter VAR Word········ ' counts the passes the servo has taken
time CON 30············· ' how long the servo holds position
Main:
one=IN0
two=IN1
three=IN2
IF one=0 THEN first
IF two=0 THEN second
IF three=0 THEN third
GOTO Main
'================================================= ================================================== =======================
first:
DEBUG "0 to 100 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 350················ 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
GOTO main
second:
DEBUG "101 to 200 lbs", CR
FOR counter = 1 TO time
PULSOUT 14, 400
PAUSE 20
NEXT
GOTO main
third:
DEBUG "201 to 300 lbs", CR
FOR counter = 1 TO time········ ' for counter = how long to hold
PULSOUT 14, 450················ 'outputs from pin 14
PAUSE 20
NEXT························ '20ms pause
GOTO main
·· DEBUG "301 to 400 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 500·············· 'outputs from pin 14
PAUSE 20
NEXT······················· '20ms pause
·DEBUG "401 to 500 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 550················ 'outputs from pin 14
PAUSE 20
NEXT····················· '20ms pause
DEBUG "501 to 600 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 600·············· 'outputs from pin 14
PAUSE 20
NEXT··················· '20ms pause
DEBUG "601 to 700 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 650·············· 'outputs from pin 14
PAUSE 20
NEXT················· '20ms pause
DEBUG "701 to 800 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14,700··············· 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
DEBUG "801 to 900 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 750··············· 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
DEBUG "901 to 1000 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 800·············· 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
GOTO main
'{$STAMP BS2}
'{$PBASIC 2.5}
' servo control
DEBUG "ready",CR
one VAR Bit············ 'state of the hall effect sensor no. 1
two VAR Bit············ 'state of the hall effect sensor no. 1
three VAR Bit·········· 'state of the hall effect sensor no. 1
'=============================
counter VAR Word········ ' counts the passes the servo has taken
time CON 30············· ' how long the servo holds position
Main:
one=IN0
two=IN1
three=IN2
IF one=0 THEN first
IF two=0 THEN second
IF three=0 THEN third
GOTO Main
'================================================= ================================================== =======================
first:
DEBUG "0 to 100 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 350················ 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
GOTO main
second:
DEBUG "101 to 200 lbs", CR
FOR counter = 1 TO time
PULSOUT 14, 400
PAUSE 20
NEXT
GOTO main
third:
DEBUG "201 to 300 lbs", CR
FOR counter = 1 TO time········ ' for counter = how long to hold
PULSOUT 14, 450················ 'outputs from pin 14
PAUSE 20
NEXT························ '20ms pause
GOTO main
·· DEBUG "301 to 400 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 500·············· 'outputs from pin 14
PAUSE 20
NEXT······················· '20ms pause
·DEBUG "401 to 500 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 550················ 'outputs from pin 14
PAUSE 20
NEXT····················· '20ms pause
DEBUG "501 to 600 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 600·············· 'outputs from pin 14
PAUSE 20
NEXT··················· '20ms pause
DEBUG "601 to 700 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 650·············· 'outputs from pin 14
PAUSE 20
NEXT················· '20ms pause
DEBUG "701 to 800 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14,700··············· 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
DEBUG "801 to 900 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 750··············· 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
DEBUG "901 to 1000 lbs", CR
FOR counter = 1 TO time·········· ' for counter = how long to hold
PULSOUT 14, 800·············· 'outputs from pin 14
PAUSE 20······················· '20ms pause
NEXT
GOTO main