highlight and others
This commit is contained in:
@ -1,10 +1,14 @@
|
||||
<!-- { "title": "Yet Another Debouncing Method" } -->
|
||||
|
||||
<h1>#title#</h1>
|
||||
<p>
|
||||
You can find several approaches for debouncing mechanical switches on the Internet, some work better, some not so good.
|
||||
</p>
|
||||
|
||||
One common approach is to ignore events in an ISR when they come too fast:
|
||||
<p>
|
||||
One common approach is to ignore events in an ISR when they come too fast:<br/>
|
||||
|
||||
[code language="C"]
|
||||
<pre><code class="C">
|
||||
void count() {
|
||||
static uint32_t lastEvent = 0;
|
||||
uint32_t currentEvent = micros();
|
||||
@ -18,26 +22,25 @@ void setup() {
|
||||
pinMode(REED_PIN, INPUT_PULLUP);
|
||||
attachInterrupt(REED_PIN, count, FALLING);
|
||||
}
|
||||
[/code]
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
This works very good when only the tipping of a switch is relevant.
|
||||
</p>
|
||||
|
||||
When also the time the button was pressed is relevant and when it is especially necessary to distinguish between a short and a long press this approach doesn't work anymore.
|
||||
<p>
|
||||
When also the time the button was pressed is relevant and when it is especially necessary to distinguish between a short and a long press this approach doesn't work anymore.<br/>
|
||||
|
||||
Since I couldn't remember the approaches I read about earlier I've sketched this state machine:
|
||||
Since I couldn't remember the approaches I read about earlier I've sketched this state machine:<br/>
|
||||
|
||||
<img src="files/20180430110848869_0001.jpg" width="500"/>
|
||||
|
||||
<!--more-->
|
||||
<br/>
|
||||
(The double-lined states are action-states which send out the related information.)<br>
|
||||
|
||||
At least for me, this approach is working very reliable so far, I'm quite happy with it.<br>
|
||||
|
||||
|
||||
<img src="https://a385e5.files.wordpress.com/2018/04/20180430110848869_0001.jpg" alt="20180430110848869_0001.jpg" width="2332" height="3307" class="alignnone size-full wp-image-901" />
|
||||
|
||||
(The double-lined states are action-states which send out the related information.)
|
||||
|
||||
At least for me, this approach is working very reliable so far, I'm quite happy with it.
|
||||
|
||||
[code language="C"]
|
||||
<pre><code class="C">
|
||||
enum tPressedState { psHIGH, psLOW, psACCEPTED_LOW, psLONG_START, psLONG_CONT, psLONG_CONT_SEND, psLONG_END, psSHORT, psINVALID };
|
||||
|
||||
typedef struct {
|
||||
@ -135,8 +138,13 @@ static void buttonHandler(tButton *button) {
|
||||
button->lastStateChange = currentMicros;
|
||||
}
|
||||
}
|
||||
[/code]
|
||||
</code>
|
||||
</pre>
|
||||
</p>
|
||||
|
||||
Find it embedded in the code of a small ESP8266-based switch thing I'm using in my home automation setup (home grown control code (https://gitlab.com/wolutator/dispatcher_ng), homegear (https://homegear.eu/) for device integration and openHAB (https://www.openhab.org/) as user interface) here: https://gitlab.com/wolutator/MySwitch.
|
||||
|
||||
')
|
||||
<p>
|
||||
Find it embedded in the code of a small ESP8266-based switch thing I'm using in
|
||||
my home automation setup (home grown control code (<a href="https://gitlab.com/wolutator/dispatcher_ng">on gitlab</a>),
|
||||
<a href="https://homegear.eu/">homegear</a> for device integration and <a href="https://www.openhab.org/">openhab</a>
|
||||
as user interface) <a href="https://gitlab.com/wolutator/MySwitch">here on gitlab</a>.
|
||||
</p>
|
||||
|
Reference in New Issue
Block a user