Detect long press of switch/tactile

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Detect long press of switch/tactile

Post by MarkW »

Hi

What methods have been used to detect the long press of a switch/tactile?
I have a project that needs to detect if a press the switch briefly or for say
3 secs, to generate different response like display a different menu on LCD
screen?

Switch bounce is not an issue, i have a dedicated hardware cct taking care of that.
Just want to know what effective methods have been used before. Also must
be able to detect any release of the switch within the long press period and reset
or restart the detection (any release of switch within the 3secs will re-start the
detection).

Thanx

Mark

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Detect long press of switch/tactile

Post by medelec35 »

Hi Mark.
If you place a switch i/p, small delay e.g 50ms and count=count+1 calculation box within a loop that is exited as soon as switch is pressed, then when loop is exited (at the end), the count variable can then determine if long or short press.
I can post an example if your stuck.

Martin
Martin

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Detect long press of switch/tactile

Post by MarkW »

Hi Martin,

Sounds like a good idea. I will try it out and see if it works in my application.

In the meantime, if you get a chance, could you show me an example
program? I have both FC V4 and V5

Thanx

Mark

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Detect long press of switch/tactile

Post by medelec35 »

Attached is one such routine.
The switch detection length routine is only short.
Rest of the flowchart was just a way to display results (loop- non timer interrupt method).
sw press1.png
(4.86 KiB) Downloaded 2974 times
The other way of length of time detection is use a timer interrupt.
When switch is first pressed reset timer counter.
When switch is released store and used the final timer counter.

Hope this helps

Martin.
Attachments
Switch Press Test.fcf
(13.95 KiB) Downloaded 294 times
Martin

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Detect long press of switch/tactile

Post by MarkW »

Hi Martin,

Thanx for the example.....will take a look and see how it works :D

Can you tell me what version FC you did this?

Thanx

Mark

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Detect long press of switch/tactile

Post by medelec35 »

Your welcome Mark,
Created with Flowcode V5.5.2.1

Martin
Martin

Post Reply