Shop OBEX P1 Docs P2 Docs Learn Events
Reas Activated Pin — Parallax Forums

Reas Activated Pin

erastuskerastusk Posts: 17
edited 2009-02-06 13:04 in BASIC Stamp
Is there a command i can use to read a pin when its activated by a switch accurately.I've tried to use pulsin and i'm not getting an accurate readings.

Thanks

Comments

  • dandreaedandreae Posts: 1,375
    edited 2009-02-04 23:52
    You can use the "IF THEN" command to monitor the state of an I/O pin.· IF IN4 = 1 THEN goto subroutine.· You can use the DEBUG command as well.



    Dave

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

    Parallax Tech Support·
  • ercoerco Posts: 20,256
    edited 2009-02-05 02:52
    erastusk: What's not intuitive is that you have to force an input pin high when you want it high and low when you want it low.· See the sketch attached, which will make your pin read low (if in4=0) when the switch is open as pictured, and the pin will read high (if in4=1) when the switch is closed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
    250 x 200 - 4K
  • erastuskerastusk Posts: 17
    edited 2009-02-05 05:07
    Hi Erco and Dave,
    I was using the if·then code you just posted and wasn't getting really reliable data.However, i was trying to mimick a switch with just a wire, so i think i might need to build an actual switching device to test it.
    Thanks guys
  • SRLMSRLM Posts: 5,045
    edited 2009-02-05 07:59
    A wire works as a switch, just be sure that you hold it tight (when debugging) so that you get less jitter in your output and you can see what happens when.
  • ercoerco Posts: 20,256
    edited 2009-02-05 16:51
    era: Something's wrong if you can't read a pin 100% reliably with this basic setup. Not sure what stamp and setup you have, but try this: connect pin 0 to ground (Vss)·through a 10K resistor, then use a wire to make & break a connection from pin0 to Vdd (NOT Vin) while running this code:

    a[noparse]:D[/noparse]EBUG IN0
    GOTO a

    you'll get 1's when you make the connection and 0's when you break it. If not, all is lost, abandon ship!

    One you verify that works, check your code for IF/THEN errors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-02-05 20:13
    I agree with Erco, but add a BIN1 to the program:
    DO
    DEBUG BIN1 IN0
    LOOP

    Eratusk, What do you mean by accurately in "read a pin when its activated by a switch accurately"? What do you want to happen when the switch is pressed and then released?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • erastuskerastusk Posts: 17
    edited 2009-02-06 13:04
    Hi Guys,
    What i meant by accurately is when i ran the if IN4 loop, i would get 1s and 0s even when the wire was not connected or get the same thing when the wire was connected.
    The problem was with the wire itself, it wasn't making contacted with the pin without moving.When i held it tightly it worked.Since I'm using a breadboard this shouldn't be a problem when i solder it.

    My Fault, thanks Guys
Sign In or Register to comment.