Shop OBEX P1 Docs P2 Docs Learn Events
tact switch — Parallax Forums

tact switch

johnprokojohnproko Posts: 121
edited 2014-05-25 14:52 in General Discussion
hello all.
i have a question regarding the tact switch.
i have plenty of those because every time i bought something they gave them.
i want to build a robotic arm that is controlled by these switches.
when i attach them to a simple circuit (battery- tact- led) they work just fine.
when i do the exactly same thing to the breadboard nothing happens... :-(
the code i use is
do
if in5= 1 then
debug "yes"
endif
loop

doesn't seem to work and i get all the time yes until it crashes.
its a four leg tact switch.
until now I'm using a force button but I'm limited to one and it doesn't always get the push
thank you in advance!

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2014-05-25 06:30
    Details, please: What's your circuit?
    +V to switch_1a, switch_1b to input pin? [That won't work.]

    It's one of the 4-legged jobs, you need to know which are the contacts.
    (People get those turned around all the time.)
  • MarkCrCoMarkCrCo Posts: 89
    edited 2014-05-25 08:54
    Your code should be fine but you might be seeing left over information because you aren't clearing the debug screen or using carriage returns. Try this:

    '
    [ Title ]
    ' {$STAMP BS2} ' Stamp directive.
    ' {$PBASIC 2.5} ' PBASIC directive.


    switch1 VAR Bit

    switch1 = 0

    DEBUG "Testing ..."

    DO

    switch1 = IN5

    IF switch1 = 1 THEN
    DEBUG HOME, CR, " pressed...", CLREOL
    ELSE
    DEBUG HOME, CR, " not pressed this time", clreol
    ENDIF
    LOOP


    Check all your wiring as PJ sugests. Try this code and let us know how it goes.
  • GenetixGenetix Posts: 1,754
    edited 2014-05-25 10:45
    A current-limiting resistor is always needed with an LED or else it will quickly die.
    Also, the program is written for an Active-High (Active state is 1) pushbutton so there needs to be a Pull-down resistor (connected to ground) for reliable operation.

    Look at the circuits and code in What's a Microcontroller and other Stamps-In-Class texts.
    P5 <--- PB ---> Vdd = 5V
    |_<--- 10K ---> Vss = Ground
  • RDL2004RDL2004 Posts: 2,554
    edited 2014-05-25 14:52
    Check your circuit carefully as PJ suggested. Those tactile switches don't work all that well in breadboards. It's probably either not making good contact or the way you have it inserted is shorting it out.
Sign In or Register to comment.