2019-06-05 11:00 AM
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?
2019-06-05 11:08 AM
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
2019-06-05 12:27 PM
Thank you for your reply. How would it be in code?
2019-06-06 08:09 AM
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.
2019-06-06 08:09 AM
2019-06-06 08:10 AM
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