PDA

View Full Version : Counting Button Pushes



Tissy
- 27th November 2005, 14:35
What is the best method of counting button pushes for a 'Mode' Select.

I have three buttons which are used in a SELECT CASE routine.

What i would like is say when button 2 is pushed this then sets a MODE.

Then depending on the amount of times that button is pushed within a three second period, defines what happens next.

So from the start, pushing button 2 once goes to routine 1, pushing it twice goes to routine 2 and pushing 3 times goes to routine 3.

What is the most reliable method of doing this, anyone used this kind of taks before in a project.

Many thanks.

Darrel Taylor
- 27th November 2005, 22:10
Hi Tissy,

Here's a possibility.   If you do the "De-bouncing" in hardware,
http://www.darreltaylor.com/files/debounce.GIF
then you can use the COUNT command

Button2 VAR PORTC.0 ' use a pin with Schmitt Trigger input
Presses VAR BYTE
Down CON 0

Main:
if Button2 = Down THEN
WHILE Button2 = Down : WEND
' Mode = Something
COUNT Button2, 3000, Presses
BRANCHL Presses,[routine0, routine1, routine2, routine3]
GOTO routine0
endif
GOTO Main

'--------------
routine0: ' button was not pressed again
' or pressed more than 3 times
GOTO Main

'--------------
routine1: ' pressed once

GOTO Main

'--------------
routine2: ' pressed twice

GOTO Main

'--------------
routine3: ' pressed thrice

GOTO Main