Shop OBEX P1 Docs P2 Docs Learn Events
servo and two pushbuttons — Parallax Forums

servo and two pushbuttons

axial28rraxial28rr Posts: 16
edited 2011-04-09 13:55 in BASIC Stamp
hello guys am new to this am learing parallax in my programing class one of the mini projects is to make a a servo go Clockwise and Counterwise with two push buttons. one button for ClockWise and another button for counter clockwise.

i was told i can modify this but i cant see to fish out the problem

this example id from what a microcontroler

' What's a Microcontroller - ServoControlWithPushbuttons.bs2

' Press and hold P4 pushbutton to rotate the servo counterclockwise,

' or press the pushbutton connected to P3 to rotate the servo clockwise.

' {$STAMP BS2}

' {$PBASIC 2.5}

duration VAR Word

duration = 750

PAUSE 1000

DO

IF IN3 = 1 THEN

IF duration > 500 THEN

duration = duration - 25

ENDIF

ENDIF

IF IN4 = 1 THEN

IF duration < 1000 THEN

duration = duration + 25

ENDIF

ENDIF

PULSOUT 14, duration

PAUSE 10

DEBUG HOME, DEC4 duration, " = duration"

LOOP

Comments

  • ercoerco Posts: 20,256
    edited 2011-04-05 15:40
    A normally low momentary pushbutton on P3, a normally low momentary pushbutton on P4 and a servo on P14. Your DEBUG statement acts sort of like a PAUSE 10 so the total pause is nearly 20 ms .

    It's all done for you. What's not to love?
  • axial28rraxial28rr Posts: 16
    edited 2011-04-05 16:11
    i try running the program and only one one button is working and it is going clockwise but for counterclock wise nothing is happeing
  • ercoerco Posts: 20,256
    edited 2011-04-05 16:23
    What's the range of numbers shown on your screen? Should go up to 1000 and down to 500 when you press the buttons.

    Check the wiring on your switches. Are you using pulldown resistors? P3 and P4 each need a ~10K resistor going to ground (Vdd), in addition to the switch that connects them to Vcc (5V).
  • graffixgraffix Posts: 389
    edited 2011-04-06 20:24
    I ran your program, it worked fine?
  • axial28rraxial28rr Posts: 16
    edited 2011-04-07 16:08
    It worked today i dont know but i must of miss wired something wich is odd for me with my background in R/C. Smile happens i guess. but know am a day behind in school. so i need to make a
    Two Led recation timer with two push buttons so to start i used this program wich is from the hand out but only one is working. i need to be able to push both of the push buttons down and when i relese one of the push buttons it sends a time but i am only geting one to work any help on programing would be helpfull

    ' What's a Microcontroller - PushbuttonControlOfTwoLeds.bs2

    ' Blink P14 LED if P3 pushbutton is pressed, and blink P15 LED if

    ' P4 pushbutton is pressed.

    ' {$STAMP BS2}

    ' {$PBASIC 2.5}

    PAUSE 1000
    DO

    DEBUG HOME

    DEBUG ? IN4

    DEBUG ? IN3

    IF (IN3 = 1) AND (IN4 = 1) THEN

    HIGH 14

    HIGH 15

    PAUSE 50

    ELSEIF (IN3 = 1) THEN

    HIGH 14

    PAUSE 50

    ELSEIF (IN4 = 1) THEN

    HIGH 15

    PAUSE 50

    ELSE

    PAUSE 50

    ENDIF

    LOW 14

    LOW 15

    PAUSE 50

    LOOP
  • axial28rraxial28rr Posts: 16
    edited 2011-04-09 13:55
    how do i get this code to read the time for both players when both buttons are released i get it to work when one button is HIGH and one button is LOW but when both are low it only puts the fastes tiime of one button but i need both to show up regardles

    Thanks Ax


    ' What's a Microcontroller - ReactionTimer.bs2[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]' Test reaction time with a pushbutton and a bicolor LED.[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]' {$STAMP BS2}[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]' {$PBASIC 2.5}[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]PAUSE 1000[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]timeCounter VAR Word[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]DEBUG"Press andhold both pushbutton", CR,[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]"to makelight turn red.", CR, CR,[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]"Whenlight turns green, let", CR,[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]"go asfast as you can.", CR, CR[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]DEBUG HOME, CR[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]DEBUG IN3, CR[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]DEBUG IN4, CR[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]DO[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]DO[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]LOOP UNTIL IN3 = 1AND IN4 = 1[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]HIGH 14[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]LOW 15[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]PAUSE 1000[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]LOW 14[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]HIGH 15[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]timeCounter = 0[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]timeCounter = 0[/SIZE][/FONT]
     
     
     
    [FONT=Calibri][SIZE=3]DO[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]PAUSE 1[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]timeCounter =timeCounter + 1[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]LOOP UNTIL IN3 = 0OR IN4 = 0[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]LOW 15[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]DEBUG "Yourtime was ", DEC timeCounter,[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]" ms.",CR, CR,[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]"To play again,hold the ", CR,[/SIZE][/FONT]
     
    [FONT=Calibri][SIZE=3]"button downagain.", CR, CR[/SIZE][/FONT]
     
    [SIZE=3][FONT=Calibri]LOOP[/FONT][/SIZE]
    [FONT=Calibri][SIZE=3]
    
Sign In or Register to comment.