Shop OBEX P1 Docs P2 Docs Learn Events
Can you put a time window for an input? — Parallax Forums

Can you put a time window for an input?

correao69correao69 Posts: 2
edited 2006-11-10 06:28 in BASIC Stamp
I have Bush button one (PB1), after that is pushed, i want to set a 6 second window for the second bush button(PB2) to be pressed. If PB2 is clicked with in the 6 seconds, it sets off leds and a buzzer, if it is pressed after the six seconds, nothing happens, and it just loops back to looking for PB 1to be pushed.· How should i do this?

Post Edited (correao69) : 11/9/2006 4:14:08 PM GMT

Comments

  • Lee HarkerLee Harker Posts: 104
    edited 2006-11-09 15:05
    Is that 6 seconds after power-up, six seconds after midnight or what? I think we'll need a few more details to help out.

    Lee
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-09 15:25
    Hello,
    ·
    ·· One thing you can do to put a timeout on the input of something is to put a counter in the loop checking the input.· Each pass through the loop increment the counter and check for the upper limit.· When reached you brand out of that loop.· I do this myself, although depending on what is happening in the loop you sometimes have to experiment with the values.· The only other way would be to use an external RTC such as the DS1302 for timing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • correao69correao69 Posts: 2
    edited 2006-11-09 16:11
    I have Bush button one (PB1), after that is pushed, i want to set a 6 second window for the second bush button(PB2) to be pressed. If PB2 is clicked with in the 6 seconds, it sets off leds and a buzzer, if it is pressed after the six seconds, nothing happens, and it just loops back to looking for PB 1to be pushed.
  • Tommy BotTommy Bot Posts: 60
    edited 2006-11-09 16:22
    It would go something like this. This is just for sequence flow, YOU check for syntax, don't forget to declaire your variables.

    Main:
    IF PushButton1 = (1 or 0 depending on how you wire it) THEN GOSUB CheckForPB2
    ' Other code goes here
    GOTO Main

    CheckForPB2:
    FOR x = 1 to 120 ' 120 iterations of PAUSE 50 = 6 seconds, - of course actual process time of code.
    IF PushButton2 = (1 or 0 depending on how you wire it) THEN Action
    PAUSE 50
    NEXT

    GOTO Main

    Action:
    Light the lights
    Sound the sounds
    Ding the Dingers

    GOTO Main

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    (Frequently heard from other's)

    Tommy, I know it wasn't designed to·x, but can you make it·do x·anyway?

    ·
  • Harry CallahanHarry Callahan Posts: 6
    edited 2006-11-09 17:43
    Consider a SERIN with timeout. You're not really doing a SERIN on PB2, but SERIN won't
    know the difference. Set up the polarity in accordance with the active low/high state of PB2,
    and pushing your button will look like a start bit. See manual for details.

    DH
  • metron9metron9 Posts: 1,100
    edited 2006-11-09 21:02
    I have another idea for you that uses external hardware.

    using 3 pins PushButton1, PushButton2 and a third pin for an R/C timer.

    Logic would be

    wait for pin1
    charge capacitor with pin3
    change pin3 back to input
    wait for pin2 to be pressed, timeout if pin3 goes low
    if pressed check if pin3 still high
    if pin3 still high it is within 6 second window


    A capacitor and resistor that will hold pin3 high for 6 seconds would be attached to pin3

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • tj60647tj60647 Posts: 18
    edited 2006-11-10 06:28
    I'd think you could do what metron9 suggests but instead of using a second pin for pushButton2 just have the pushbutton short the R/C circuit [noparse][[/noparse]to ground], if the RCtime is less than 6 seconds [noparse][[/noparse]6000ms] then the button was pressed. Check out the schematics under RCTIME in the PBASIC Syntax Guide.
Sign In or Register to comment.