Press button for certain of time
Bronson
Posts: 44
Hi,
How can I code: IF button is pressed for 3 sec THEN GOTO procedure1
Can I use BUTTON command? I don't quite understand this BUTTON command.
I am asking this because I am doing a project, but the input pin seems very unstable.
The input can change state by itself even if the button is not pressed at all.
I am using active-low connection for push-button with 10k resistor tied to Vdd.
My testing code is:
=======
start:
DEBUG BIN IN0
GOTO start
=======
The result when the button is not pressed at all:
111111011111111011110111111111011111111111111111
Pls help me....
Regards,
Bronson
How can I code: IF button is pressed for 3 sec THEN GOTO procedure1
Can I use BUTTON command? I don't quite understand this BUTTON command.
I am asking this because I am doing a project, but the input pin seems very unstable.
The input can change state by itself even if the button is not pressed at all.
I am using active-low connection for push-button with 10k resistor tied to Vdd.
My testing code is:
=======
start:
DEBUG BIN IN0
GOTO start
=======
The result when the button is not pressed at all:
111111011111111011110111111111011111111111111111
Pls help me....
Regards,
Bronson
Comments
To test for a button held down for a period of time, you need to keep testing the button in a loop, every 1/10 second or 1/4 second or something like that and keep a count of the number of times it's been tested. If the button goes off, then exit the loop. If the total time (count x delay) is greater than your limit, then you have success. Substitute IN0 or IN1 or whatever for button in the following:
Leon,
The input will change state by itself every approx 30sec-4min.
I think you were right...it seems like my input is picking up noise as I am putting my PCB inside a panel loaded with relays, cables, and contactors. But only 1 input is having this problem. The other 7 inputs work perfectly. If it is noise problem, how can I fix it? Can I use shielded cables for the input cable?
Mike,
Thanks alot for the code, I have saved it already.
By the way, while searching this forum, I found a link posted by PJ Allen:
http://forums.parallax.com/attachmen...chmentid=42013
Is it relevant to my problem?
I do all of my inputs or switches this way
in the past I have use this setup to do two different thing with one switch different cntr = values some time this is not easy to do how ever
you also try this this works very well
' {$STAMP BS2}
' {$PBASIC 2.5}
'
'
chg PIN 1
cntr VAR Byte
'
'
DO
'
cntr = cntr + 1 * Chg ' Input must = 1 for couter to count
IF (cntr = 5) THEN EXIT ' cntr = 1 to 255 count can be any thing in that range
'
'OR
'
cntr = cntr + 1 * (1 - Chg) ' Input must = 0 for couter to count
IF (cntr = 255) THEN EXIT
'
LOOP
Erco,
Why didn't I think of that simple trick? Thx for the advice..Will do as you say.
Leon,
Can you please send me pic of the connection using 100nF cap? Just to be sure
Sam,
Thx for the code and pic, I will try your idea
Mike,
I will change the resistor as you say
Hope that one of the suggestion will work....
Regards,
Bronson