PDA

View Full Version : Can you put a time window for an input?



correao69
11-09-2006, 10:52 PM
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

Lee Harker
11-09-2006, 11:05 PM
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 Savage
11-09-2006, 11:25 PM
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

correao69
11-10-2006, 12:11 AM
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 Bot
11-10-2006, 12:22 AM
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 Callahan
11-10-2006, 01:43 AM
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

metron9
11-10-2006, 05:02 AM
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!

tj60647
11-10-2006, 02:28 PM
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 [to ground], if the RCtime is less than 6 seconds [6000ms] then the button was pressed. Check out the schematics under RCTIME in the PBASIC Syntax Guide.