stepper motor in a loop
i am trying to have a stepper motor do 40 steps clockwise when the input goes high, then do nothing until the input goes low. the low would then turn the motor 40 steps counterclockwise.
i have the stepper motor turning in both directions. i am stuck on on what to do next. i need the program to keep checking if the input has changed.
thanks,
e
i have the stepper motor turning in both directions. i am stuck on on what to do next. i need the program to keep checking if the input has changed.
thanks,
e

Comments
PAR
·
·· All you need to do is have a conditional in your loop checking the status of the input.· When it is HIGH you GOSUB to a subroutine to step the Stepper Motor one way then return.· The ELSEIF section of the conditional will call the reverse subroutine which moves 40 steps.· This assumes you don’t need to stop once you start the 40 steps.· But the loop would do nothing until the input changed.
·
·· The other part of this equation is a flag variable.· This flag will be set when one routine runs and cleared when the other runs.· Your IF…THEN routine will check the state of the input AND the flag.· I will see if I can explain with some sample code…
' {$STAMP BS2} ' {$PBASIC 2.5} Sensor PIN 0 flag VAR bit index VAR byte do IF Sensor = 1 AND flag = 0 THEN GOSUB Step_Forward flag = 1 ELSEIF Sensor = 0 AND flag = 1 THEN GOSUB Step_Reverse flag = 0 endif loop Step_Forward: FOR index = 0 TO 39 ' Code to handle Stepper Motor NEXT return Step_Reverse: FOR index = 0 TO 39 ' Code to handle Stepper Motor next return▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
one more question.....how do i compare variables (ex. dsdata and s1)
what i want them to do is if they are the same out10 goes low.· if they are different out10 goes high.·
thanks
e
·
·· This should work fine…Take care.
' {$STAMP BS2} ' {$PBASIC 2.5} dsData VAR byte s1 VAR byte do IF dsData = s1 then LOW 10 ELSE HIGH 10 endif loop▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support