cancel
Showing results for 
Search instead for 
Did you mean: 

Double press, long and short press

HNdal
Associate III

Hi all,

I am using the stm8l152c6 discovery board which has one user button.

I would like to implement that the button pressed once, blink the led, when pressed twice, the led off, also button pressed for 5 sec or less than 5 sec, do somthing.

Please assist or where can I find the relevant information?

5 REPLIES 5
S.Ma
Principal

Basically in the main loop, check the pin level every 50+ msec.

Say key is pressed cause low level.

Increment a counter when the pin is low level and it was too 50 msec ago.

Reset the counter when high level is detected.

Now you can consider debounce and have key pressed event after say 3x50 msec

If the key is pressed 5 sec = counter reaches 50x1000=50000 (16 bit).

And instead of press twice detection, just toggle the LED when pressed. Simpler.

Read about Analog Keyboards: use of ADC and resistor divider with keys to 5 buttons with 1 analog wire

HNdal
Associate III

Thank you for your reply. How would it be in code?

S.Ma
Principal

This might not help so much as it's an old code for analog and matrix keyboard used over and over for STM8L151 or STM32.

Just for reading.

Analog keyboard make several keys to change a resistor divider going to ADC. A voltage range correspond to one of the key.

Usually 4 keys can be put to one ADC input.

S.Ma
Principal

second file

S.Ma
Principal

Wonder why we can't put multiple files on the same answer. A regression vs Jive. It's a bit of a pain to make a zip too