Button press
SMenn
Posts: 16
in BASIC Stamp
Hi everyone,
I am trying to create a mini pinball table with my BS2, I would like to create a code where the servo turns a certain distance when I press a momentary contact switch, then goes back to it's original position when I release. I have tried to program this for about three days now, and I cannot figure it out. For now, we can say the switch is wired to IN0, and the servo is plugged in to 12. I can change the code later if I need to. Can someone help me to code this?
Below is my current code.
Thanks for the help.
counter VAR byte
DO
IF (IN0 = 0) THEN
GOSUB up
ENDIF
IF (IN0 = 1) THEN
GOSUB down
ENDIF
LOOP
up:
FOR counter = 1 TO 25
PULSOUT 12, 850
NEXT
RETURN
down:
FOR counter = 1 TO 25
PULSOUT 12, 650
NEXT
RETURN
END
I am trying to create a mini pinball table with my BS2, I would like to create a code where the servo turns a certain distance when I press a momentary contact switch, then goes back to it's original position when I release. I have tried to program this for about three days now, and I cannot figure it out. For now, we can say the switch is wired to IN0, and the servo is plugged in to 12. I can change the code later if I need to. Can someone help me to code this?
Below is my current code.
Thanks for the help.
counter VAR byte
DO
IF (IN0 = 0) THEN
GOSUB up
ENDIF
IF (IN0 = 1) THEN
GOSUB down
ENDIF
LOOP
up:
FOR counter = 1 TO 25
PULSOUT 12, 850
NEXT
RETURN
down:
FOR counter = 1 TO 25
PULSOUT 12, 650
NEXT
RETURN
END
Comments
Thanks for the help, but my servos are continuous rotation. so when the switch is pressed it runs one way, and when I let off it runs the other way. I would like it to turn about a quarter turn the stop both ways, which is why I used the counter variable. Any ideas?
I get what you are saying, how do I tell it to pause when I get an on or off pulse?
Thanks!
What standard servo would you recommend?
It has to be fast and strong enough to hit the pinball.
As erco hinted at, a solenoid is an inductive load, so depending on the driver additional protection may be required.
http://forums.parallax.com/discussion/143792/using-basic-stamp-with-electric-solenoid-valve-need-help
Yes that link was helpful. What voltage solenoid would be powerful enough to knock the pinball all the way up the board?
https://www.adafruit.com/products/412?gclid=CjwKEAjwu6a5BRC53sW0w9677RcSJABoFn4sNN58qG-1XLwOMjuXfd5biLOkgbemVmmBKICy45EptRoC2sXw_wcB
Start with 6 volt first.
Trying things to see if they work. Worst case.
i found this for running solenoids with arduino. Would it work with a bs2 on the BoE as well?
Thanks
Sam