How do I connect a switch to act as the reset button on my board of education
mimic
Posts: 1
I have a program that turns a servo counterclockwise so many pulses and then clockwise so many pulses.
I want to have a switch that will start the program every time I hit the switch or button.
Here is the code for my servo· I am sure that I will have to add to it to make the button work.
Any advice
·' What's a Microcontroller - ServoTest.bs2
' Test the servo at three different position signals.
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 1000
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 500
PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
DEBUG "All done."
END
I want to have a switch that will start the program every time I hit the switch or button.
Here is the code for my servo· I am sure that I will have to add to it to make the button work.
Any advice
·' What's a Microcontroller - ServoTest.bs2
' Test the servo at three different position signals.
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 1000
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 500
PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
DEBUG "All done."
END
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
There are other, maybe simpler ways to do this too, such as using INPUT, with a DO WHILE or DO UNTIL type of loop.· It's up to you, this is just a suggestion.
' What's a Microcontroller - ServoTest.bs2 with pushbutton control
' Test the servo at three different position signals.
' {$STAMP BS2}
' {$PBASIC 2.5}
PressMe PIN 14·· 'change to reflect pin number of your button.
State1 CON·1·····'change to reflect button's pressed state, 0 or 1, see BUTTON command for more info, this·assumes button is wired to VDD
State2 CON 1·····'for this example, don't change, we want to branch only if the button is pressed.
BtnWork VAR WORD·· ·'workspace for BUTTON command
counter VAR Word····· 'orginal program variable
MAIN:
DO
BUTTON, PressMe, State1, 255, 20, BtnWork, State2, SERVO
LOOP
SERVO:
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 1000
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 500
PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
DEBUG "All done."
RETURN
Post Edited (Desy2820) : 10/21/2007 10:28:56 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--DFaust