Shop OBEX P1 Docs P2 Docs Learn Events
Waiting for input — Parallax Forums

Waiting for input

CranzCranz Posts: 9
edited 2006-08-07 16:00 in BASIC Stamp
Hello!

How can I program this situation?

"If button is pressed whitin 5 seconds, jump to some sort of label."

anybody knows?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-07 08:50
    Cranz -

    The PBASIC Stamp does not have any interrupt capability, nor is there an accessable RTC. however, if you can use SERIN to field your input SERIN permits a "timeout label" to be used. If you were using (say) a PBASIC Stamp BS-2 you'd set the Timeout value to 5000 mS (5 seconds) and place an appropriate label in the Tlabel field.

    Alternatively, you can certainly add an inexpensive RTC with an alarm feature, and poll it to see if 5 seconds has expired.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • T ChapT Chap Posts: 4,223
    edited 2006-08-07 08:56
    Within 5 seconds of what?
  • T ChapT Chap Posts: 4,223
    edited 2006-08-07 09:04
    If you mean for example, an LED turns ON and you have 5 seconds to press a button, then you could do this:


    LedEvent:
    LED = 1
    For Counter = 1 to 50
    Counter = Counter + 1
    Pause 100
    If Button = 1 then ButtonPressed
    Next
    Goto Main


    ButtonPressed:
    'do some stuff here
  • CranzCranz Posts: 9
    edited 2006-08-07 09:17
    smart solutiojn orginator! [noparse]:D[/noparse]
  • T ChapT Chap Posts: 4,223
    edited 2006-08-07 16:00
    If timing is more critical on the button response:

    LedEvent:
    LED = 1
    Counter = 0 'reset counter which has byte value variable
    For Counter = 1 to 500
    Counter = Counter + 1
    Pause 10 'may not be precisely 5 seconds, check and adjust as needed
    If Button = 1 then ButtonPressed
    Next
    Goto Main


    ButtonPressed:
    'do some stuff here



    This version looks at the button with 10 times more resolution, or 5000 : 1 (1 being a millisecond)
Sign In or Register to comment.