Shop OBEX P1 Docs P2 Docs Learn Events
Push button controller — Parallax Forums

Push button controller

KojanowKojanow Posts: 2
edited 2008-08-15 22:27 in Learn with BlocklyProp
I am making a project with two servo's and two pushbuttons, one to acuate each servo.· The servo's are moving fine but I can't get teh push buttons to control them.
This what I have· HELP!
·' {$STAMP BS2}
' {$PBASIC 2.5}
counter·· VAR·· Word
pulses··· VAR·· Word
duration· VAR·· Word
Main:
·IF (IN2 = 1) THEN
·HIGH 0
·PAUSE 50
·LOW 0
·PAUSE 50
·ENDIF
·DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 15, 750
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 15, 150
PAUSE 20
NEXT
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 15, 750
PAUSE 20
NEXT
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 08, 750
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 08, 150
PAUSE 20
NEXT
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 08, 750
PAUSE 20
NEXT
DO
LOOP

Comments

  • Steph LindsaySteph Lindsay Posts: 767
    edited 2008-08-15 00:01
    Hi Kojanow,

    Are you starting with What's a Microcontroller, Chapter 4, Activity #4? It shows how to use two pushbuttons and one servo, one pushbutton makes it turn one way, the other pushbutton makes it turn the other way.

    The important thing is to have your pushbutton state trigger an action. In the program above, your if-then statement for your pushbutton (if it is connected to P3) only causes P0 to turn on and off once. There is no relationship to your servos on P8 and P15.

    Stephanie
  • SRLMSRLM Posts: 5,045
    edited 2008-08-15 00:26
    You'd do better to sort everything into methods. A good start would be to have a _Main method, _Rotate_Servo_1, and _Rotate_Servo_2. That way you can keep everything clear and easy to debug.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2008-08-15 15:55
    I agree with SRLM that organization would be helpful here. In PBASIC you would be using subroutines. What's a Microcontroller? introduces subroutines on page 206.
  • KojanowKojanow Posts: 2
    edited 2008-08-15 16:10
    Thanks all, I will be working on this tonight.

    Eric
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-08-15 22:27
    Duplicate post in BASIC Stamp Forum removed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.