2 push buttons on a servo
mcm1822
Posts: 4
in BASIC Stamp
Ive been trying to get a servo to operate using a push button to move it in the clockwise direction and a separate one to operate in the counter clockwise direction. the trick is that each time one of the buttons is pressed the servo will move 20 degrees and STOP, relative to the button pressed. there needs to be a total of 8 positions. Any help would be greatly appreciated.
Comments
As a general rule, we typically won't provide full code examples for students working on school assignments.
If you provide what code you've written so far and tell us where you are stuck then someone may be able to give you tips or assistance to get you moving in the right direction.
First one:
Duration VAR Word
Duration = 750
PAUSE 1000
DO
IF IN = 1 THEN
IF duration > 500 THEN
duration = duration - 25
ENDIF
ENDIF
IF IN4 = 1 THEN
IF duration < 1000 THEN
duration = duration + 25
END IF
ENDIF
PULLOUT 14, duration
Pause 10
Loop
This causes the servo to respond to the push buttons but they don't stop at any particular point.
Your program has a few errors that F7 (Check Syntax) will find.
1.) In the first IF...THEN, the IN is missing the pin number.
2.) The 2nd to last ENDIF is a one word command, not 2 separate words.
3.) The servo command is PulsOut, not PullOut.
A DO...LOOP will run forever until you remove the power or download another program.
Also, use the C icon on the posting toolbar to attach code so the formatting isn't mangled.
Since he described what the program did, I just assumed he had some typos when he entered it into the forum comment.
mcm, you can copy and paste your program. Stick it between the code markers you get when you press the C button on the format bar.