Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
DebouncedDualButton.cpp
1 #include <Arduino.h>
2 #include "DebouncedDualButton.h"
3 #include "MutilaDebug.h"
4 #include "Millis.h"
5 
7  DualInputButton(button1, button2)
8 {
9 }
10 
11 void DebouncedDualButton::begin(bool callBeginInChildren, uint8_t threshold, uint8_t delay)
12 {
13  AbstractDebouncedButton::begin(threshold, delay);
14  DualInputButton::begin(callBeginInChildren);
15 }
16 
18 {
19  if (DoEvery(_delay, _lastUpdate)) {
20  if (DualInputButton::on() != _state) {
21  _counter++;
22  if (_counter > _threshold) {
23  setState(!_state);
24  }
25  } else if (_counter > 0) {
26  _counter = 0;
27  }
28  }
29 }
30 
32 {
33  return _state;
34 }
35 
virtual void begin()
DebouncedDualButton(AbstractButton &button1, AbstractButton &button2)