Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
src
DebouncedDualButton.cpp
1
#include <Arduino.h>
2
#include "DebouncedDualButton.h"
3
#include "MutilaDebug.h"
4
#include "Millis.h"
5
6
DebouncedDualButton::DebouncedDualButton
(
AbstractButton
& button1,
AbstractButton
& button2) :
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
17
void
DebouncedDualButton::update
()
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
31
bool
DebouncedDualButton::on
()
32
{
33
return
_state;
34
}
35
DualInputButton
Definition:
DualInputButton.h:18
DualInputButton::on
bool on()
Definition:
DualInputButton.cpp:19
DebouncedDualButton::on
bool on()
Definition:
DebouncedDualButton.cpp:31
AbstractButton
Definition:
AbstractButton.h:10
AbstractButton::begin
virtual void begin()
Definition:
AbstractButton.h:23
AbstractDebouncedButton::setState
void setState(bool newState)
Definition:
AbstractDebouncedButton.cpp:58
DebouncedDualButton::update
void update()
Definition:
DebouncedDualButton.cpp:17
DebouncedDualButton::DebouncedDualButton
DebouncedDualButton(AbstractButton &button1, AbstractButton &button2)
Definition:
DebouncedDualButton.cpp:6
Generated by
1.8.15