Shop OBEX P1 Docs P2 Docs Learn Events
Using Buttons to Initiate Subroutines — Parallax Forums

Using Buttons to Initiate Subroutines

NicolidenNicoliden Posts: 1
edited 2009-06-04 18:41 in Robotics
I've been at it for several days now and I know Im just missing some small detail, but I want to put an open switch button on the breadboard and use it to initiate a Subroutine.

ex.

DO

IF (IN1= 1) THEN

GOSUB A

ELSE

PAUSE 200

ENDIF

IF (IN2= 1) THEN

GOSUB B

ELSE

PAUSE 200

ENDIF

LOOP


Is there a more standard way for using buttons, or how could I at least make it differentiate between 1 and 0? Its not very neat or practical to use the wiskers, they get in the way, and I dont want to wrap a wire around the chassis, lol.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Keep Moving Forward."

Comments

  • SamMishalSamMishal Posts: 468
    edited 2009-06-04 16:09
    I think your problem is the switch. You need to have a Pull-up or Pull down

    on the switch. If you leave an input pin floating you can get noise on the

    pin that will cause·random 0 or 1 states.



    See·the attached image

    Sam






    Post Edited (SamMishal) : 6/4/2009 4:37:03 PM GMT
    506 x 302 - 46K
  • kwinnkwinn Posts: 8,697
    edited 2009-06-04 18:41
    Even with a pull up/down resistor you may have problems because the switch "bounces" and gives several high/low transitions each time you press it. Unless the "in1" BS2 command automatically debounces the switch you will have to do so in hardware or software.
Sign In or Register to comment.