Shop OBEX P1 Docs P2 Docs Learn Events
Pollwait? — Parallax Forums

Pollwait?

ArchiverArchiver Posts: 46,084
edited 2003-11-15 00:22 in General Discussion
In below program, I noticed that if I press & hold button connected
to pin 15, then LED connected to pin 14 toggles every 1.1 sec. as
expected.

But, I also noticed that sometimes even a quick press (to bring level
of pin 15 to 0) will toggle LED.

Does anyone know what exactly the POLLWAIT 6 does? When does the
1152 msec of napping begin exactly?

'{$STAMP BS2p}
'{$PBASIC 2.5}

POLLIN 15, 0
POLLMODE 2

Loop1:
DEBUG "waste", CR
POLLWAIT 6
TOGGLE 14
'RUN 1
GOTO Loop1
END

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-14 20:52
    This is right out of the online help file and should answer your
    question:

    The POLLWAIT command is unique among the polling commands in that it
    actually causes execution to halt, until a polled-input pin event
    occurs. The Duration argument is similar to that of the NAP command;
    using the values 0 to 7 specifies the duration of the low-power period.
    After the low-power period is over, the BASIC Stamp polls the
    polled-input pins and determines if any meet the desired poll state. If
    no polled-input is in the desired state (as set by POLLIN command) the
    BASIC Stamp goes back into low-power mode, again, for the same duration
    as before. If any polled-input is in the desired state, however, the
    BASIC Stamp will continue execution with the next line of code.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office






    Original Message
    From: basicstampede [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=YRw0mFnJcMd90aNuTE6C7UYfc1aDiFLBKYDgCv0LHumL1d6QAAF0KFFKngo6JL8YMet8z3L59jXKx3IgrHA]basicstampede@y...[/url
    Sent: Friday, November 14, 2003 2:06 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Pollwait?


    In below program, I noticed that if I press & hold button connected
    to pin 15, then LED connected to pin 14 toggles every 1.1 sec. as
    expected.

    But, I also noticed that sometimes even a quick press (to bring level
    of pin 15 to 0) will toggle LED.

    Does anyone know what exactly the POLLWAIT 6 does? When does the
    1152 msec of napping begin exactly?

    '{$STAMP BS2p}
    '{$PBASIC 2.5}

    POLLIN 15, 0
    POLLMODE 2

    Loop1:
    DEBUG "waste", CR
    POLLWAIT 6
    TOGGLE 14
    'RUN 1
    GOTO Loop1
    END



    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/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-15 00:22
    >In below program, I noticed that if I press & hold button connected
    >to pin 15, then LED connected to pin 14 toggles every 1.1 sec. as
    >expected.
    >
    >But, I also noticed that sometimes even a quick press (to bring level
    >of pin 15 to 0) will toggle LED.
    >
    >Does anyone know what exactly the POLLWAIT 6 does? When does the
    >1152 msec of napping begin exactly?
    >
    >'{$STAMP BS2p}
    >'{$PBASIC 2.5}
    >
    >POLLIN 15, 0
    >POLLMODE 2
    >
    >Loop1:
    > DEBUG "waste", CR
    > POLLWAIT 6
    > TOGGLE 14
    > 'RUN 1
    >GOTO Loop1
    >END


    If you happen to press the button at the instant pollwait tests the
    pin, then it will run on through and toggle pin 14 and around the
    loop until it hits the pollwait 6 command again. Then it strings
    together successive naps of about 1 second each, stuck at the
    pollwait command, until it detects that the button is pressed again.
    It only tests the input pin at the end of each one second nap, not
    during the nap.

    For your amusement, here is a variation that blinks the led once each
    time you press or release the button. The POLLIN command is moved
    inside the loop, and the POLLIN condition is based on the current
    state of the input. So POLLWAIT drops through to the PULSOUT
    whenever the button changes state. It is more power efficient than
    looping continuously.

    '{$STAMP BS2p}
    '{$PBASIC 2.5}

    POLLMODE 2

    DO
    DEBUG bin in15
    POLLIN 15,~in15
    POLLWAIT 4 ' 1/4 second latency
    PULSOUT 14,8192
    LOOP
    END

    -- regards,
    Tracy
Sign In or Register to comment.