Shop OBEX P1 Docs P2 Docs Learn Events
Rotating servo with pushbutton — Parallax Forums

Rotating servo with pushbutton

hmillerhmiller Posts: 17
edited 2011-07-05 08:38 in BASIC Stamp
Hi,

I've been working on this for a while now and i can't find a thread that gives me an answer.
So I was wondering if someone knew the answer for a simple fix.

I have my servo plugged in and the button plugged in. I know they both work because when i run a code and the servo rotates and when i push my button it stops. I want the total opposite, I want it so that when i push the button, the continuous servo runs for as long as i say it too and then stops, and I want this to keep repeating so that if someone pushes it again it will do the same over and over.

Here's the two codes that i'm trying to use from the book "what's a microcontroller":




Code 1:

' {$STAMP BS2}
' {$PBASIC 2.5}

DEBUG ? IN1

counter VAR Word

DO

IF (IN1 = 1) THEN

DEBUG "Vending...", CR

FOR counter = 1 TO 150
PULSOUT 2, 1000
PAUSE 20
NEXT

DEBUG "Thank you!"

ELSE
PAUSE 100

ENDIF

LOOP


Code 2:


' {$STAMP BS2}
' {$PBASIC 2.5}

DEBUG ? IN1

counter VAR Word

IF IN1 = 1 THEN

DEBUG "Vending...", CR

FOR counter = 1 TO 150
PULSOUT 2, 1000
PAUSE 20
NEXT

DEBUG "Thank you!", CR

ENDIF



Please help!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-07-05 08:38
    "IF IN1 = 1 THEN" tests the input state of pin 1. If pin 1 is high, then it succeeds. You didn't say (but I'm guessing) that you've wired up your pushbutton so that pushing the button makes the pin go low (to ground). You have two choices: 1) You can change your wiring so the pushbutton makes the pin go high. 2) You can change the "1" to a "0".
Sign In or Register to comment.