PDA

View Full Version : Button Delay, Reset type functionality



DShannon
03-04-2005, 09:52 AM
Hi all,
A question that i'm sure someone can help with.

With 1 button input to the stamp, I need to perform 2 functions, based on the following rule:

1) If button is held down for 3 seconds, function "X" is performed
2) else, function "Y" is performed if button is pushed for only 100 ms

This would be like a digital clock in a car - If I hold down the button, I enter clock setting mode. however, If i momentarily press the same button, the clock changes modes (ie, shows the calendar date)

I have racked my brain and tried different IF THEN logic, but cant seem to get it, even a "hack"!

Any ideas????

Thanks!
-Dan

DShannon
03-04-2005, 09:54 AM
Also, funtion "Y" should be performed immediately.....

TimTech
03-04-2005, 11:01 AM
It would be something like this in psudocode:

1) Wait until button is pressed
2) Set a variable to 0 ("Timer" for example)
3) Wait until button is released, incrementing Timer each time through
4) If Timer > 3 seconds Then "X"
5) Else if Timer < 100ms Then "Y"
6) GOTO 1)

Post Edited (TimTech) : 3/4/2005 3:03:32 AM GMT

Tracy Allen
03-04-2005, 11:11 AM
There is quite a bit of this kind of coding in the first couple of chapters of the "Applied Sensors" text available for free download at the Parallax web site.

Something like this:
ticks VAR Byte



top:
DO
' put other program stuff here
LOOP UNTIL in0=0 ' until the button input is pressed

DO
ticks=ticks+1
IF ticks>60 THEN setClock ' jump after 3 seconds
pause 50 ' units of 50millisecs
LOOP UNTIL in0=1 ' until the button is released

SELECT ticks
CASE < 3 ' less than 150 ms
GOTO changeMode
CASE > 3 ' what happens if it is between 0.15 and 3 seconds?
GOTO whatever
ENDSELECT

setClock:
' do it
DO : LOOP UNTIL in0=1 ' to wait for user to release button
GOTO top

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

DShannon
03-04-2005, 09:52 PM
AAhhhhh! yes. this makes sense. Thanks for your help! I will give it a go........