Shop OBEX P1 Docs P2 Docs Learn Events
Using buttons — Parallax Forums

Using buttons

Steve-OSteve-O Posts: 8
edited 2005-06-04 20:50 in BASIC Stamp
I'm trying to make a servo activate by a button push. So far it's not going well... I'm using the BUTTON command inside a loop in main. When the button is activated it goes to an outside function in order to activate the servo. Here is the code I have so far...it clears the tokenizer and I have inserted several debugs inorder to see where the program is at. Disregard the counter...that's for a later project (which im sure I'll need help on too..haha)
If all this looks ok, how do you go about the circuit for this?

Comments

  • dandreaedandreae Posts: 1,375
    edited 2005-06-04 20:50
    You may be able to use an "IF THEN" command based on the condition of the input pin.· Example:

    Do

    ·IF IN1=1 THEN Arm_Servo

    Main:
    · DEBUG "main 1",CR
    · DEBUG "counter modulus: ", SDEC counter // 2 ,CR
    · DO
    · PAUSE 1000
    · BUTTON Btn, 0, 255, 20, btnWrk, 0, Arm_Servo
    · DEBUG "main 2",CR
    · LOOP


    Arm_Servo:
    · DEBUG "arm 1",CR
    · IF counter // 2 > 0 THEN x = 260 ELSE x = 1240
    ··· ra = 7: ch = 11
    ··· pw = x
    ··· DEBUG "pulse width: ", SDEC pw,CR
    ··· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC",ch,ra,pw.LOWBYTE,pw.HIGHBYTE,CR]
    ··· PAUSE 1000
    ··· pw = 760
    ··· DEBUG "pulse width at rest: ", SDEC pw,CR
    · counter = counter + 1
    · DEBUG "counter: ", SDEC counter,CR
    RETURN

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com

    ·
Sign In or Register to comment.