One comment

  • Hello Francesco,
    Cool blog!

    I often use a variation of the Approach 1:

    1 Setup a counter variable, initialise to zero.
    2 Setup a regular sampling event, perhaps using a timer. Use a period of about 1ms.

    3 On a sample event:
    4 if switch signal is low then
    5 Reset the counter varaible to zero
    6 Set internal switch state to pressed
    7 else
    8 Increment the counter variable to a maximum of 10
    9 end if
    10 if counter=10 then
    11 Set internal switch state to released
    12 end if

    In this case when you press the button, the “pressed” value is instantly obtained, then filter the “high state/release” bounces.
    Pro: get “pressed” state sooner.
    Cons: maybe little more computation time. Works well only with clean digital signals, not with noisy-analog sourced triggered signals.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.