Skip to main content
Visitor II
June 5, 2019
Question

Double press, long and short press

  • June 5, 2019
  • 5 replies
  • 2698 views

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?

    This topic has been closed for replies.

    5 replies

    Visitor II
    June 5, 2019

    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

    HNdalAuthor
    Visitor II
    June 5, 2019

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

    Visitor II
    June 6, 2019

    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.

    Visitor II
    June 6, 2019

    second file

    Visitor II
    June 6, 2019

    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