Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
src
DebouncedButton.cpp
1
#include <Arduino.h>
2
#include "DebouncedButton.h"
3
#include "MutilaDebug.h"
4
#include "Millis.h"
5
6
DebouncedButton::DebouncedButton
(uint8_t pin,
bool
pullup) :
7
DigitalInputButton
(pin, pullup)
8
{
9
}
10
11
void
DebouncedButton::begin
(uint8_t threshold, uint8_t delay)
12
{
13
AbstractDebouncedButton::begin
(threshold, delay);
14
DigitalInputButton::begin
();
15
}
16
17
void
DebouncedButton::update
()
18
{
19
if
(DoEvery(_delay, _lastUpdate)) {
20
if
(
DigitalInputButton::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
DebouncedButton::on
()
32
{
33
return
_state;
34
}
35
DigitalInputButton::begin
void begin()
Definition:
DigitalInputButton.cpp:10
DigitalInputButton::on
bool on()
Definition:
DigitalInputButton.cpp:19
DebouncedButton::DebouncedButton
DebouncedButton(uint8_t pin, bool pullup=true)
Definition:
DebouncedButton.cpp:6
AbstractButton::begin
virtual void begin()
Definition:
AbstractButton.h:23
AbstractDebouncedButton::setState
void setState(bool newState)
Definition:
AbstractDebouncedButton.cpp:58
DebouncedButton::update
void update()
Definition:
DebouncedButton.cpp:17
DebouncedButton::on
bool on()
Definition:
DebouncedButton.cpp:31
DigitalInputButton
Definition:
DigitalInputButton.h:14
Generated by
1.8.15