Shop OBEX P1 Docs P2 Docs Learn Events
Pushbutton (on/off) — Parallax Forums

Pushbutton (on/off)

ArchiverArchiver Posts: 46,084
edited 2002-07-04 18:26 in General Discussion
I know this has to be simple, but I just can't seem to get it.

I am using a BS2SX and a NX 1000 Experiment Board.

I want to turn an LED on with one push of a button, then turn it off again
with a push of the same button...........Reliably. The time it is pushed
allows a debounce routine (working fine).

Help please!

Lee
--
Registered Linux user #223705

Give me ambiguity or give me something else.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-07-04 17:08
    You can use the Stamp's ability to alias variables and the bit invert
    operator to make this easy. Let's say your LED is on pin 0:

    MyLED VAR Out0

    Init:
    OUTPUT 0

    The code above names your pin and sets its direction to output. After you
    debounce the switch, you can invert the state of the LED like this:

    MyLED = ~MyLED

    It's that simple.

    -- Jon Williams
    -- Parallax


    In a message dated 7/4/02 9:51:24 AM Central Daylight Time,
    dlwiggers@a... writes:


    > I know this has to be simple, but I just can't seem to get it.
    >
    > I am using a BS2SX and a NX 1000 Experiment Board.
    >
    > I want to turn an LED on with one push of a button, then turn it off again
    > with a push of the same button...........Reliably. The time it is pushed
    > allows a debounce routine (working fine).
    >
    > Help please!
    >
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-07-04 18:26
    Thanks Jon. I have turned the LED on and off neatly now, but what I need is
    one step further.

    I don't want to change states if I hold the button on. Then regardles of the
    time element, I release the button, then push it again and it turns the LED
    off.

    I have programmed PLC's for years, so I have some learning and unlearning to
    do.

    I appreciate your help.

    Lee

    > You can use the Stamp's ability to alias variables and the bit invert
    > operator to make this easy. Let's say your LED is on pin 0:
    >
    > MyLED VAR Out0
    >
    > Init:
    > OUTPUT 0
    >
    > The code above names your pin and sets its direction to output. After you
    > debounce the switch, you can invert the state of the LED like this:
    >
    > MyLED = ~MyLED
    >
    > It's that simple.
    >
    > -- Jon Williams
    > -- Parallax
    >
    >
    > In a message dated 7/4/02 9:51:24 AM Central Daylight Time,
    >
    > dlwiggers@a... writes:
    > > I know this has to be simple, but I just can't seem to get it.
    > >
    > > I am using a BS2SX and a NX 1000 Experiment Board.
    > >
    > > I want to turn an LED on with one push of a button, then turn it off
    > > again with a push of the same button...........Reliably. The time it is
    > > pushed allows a debounce routine (working fine).
    > >
    > > Help please!
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    > Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

    --
    Registered Linux user #223705

    Give me ambiguity or give me something else.
Sign In or Register to comment.