Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
src
DebouncedAnalogButton.cpp
1
#include <Arduino.h>
2
#include "DebouncedAnalogButton.h"
3
#include "Millis.h"
4
5
DebouncedAnalogButton::DebouncedAnalogButton
(
const
uint8_t pin,
const
bool
pullup,
const
uint16_t analogThreshold) :
6
AnalogInputButton
(pin, pullup, analogThreshold)
7
{
8
}
9
10
void
DebouncedAnalogButton::begin
(uint8_t threshold, uint8_t delay)
11
{
12
AbstractDebouncedButton::begin
(threshold, delay);
13
AnalogInputButton::begin
();
14
}
15
16
void
DebouncedAnalogButton::update
()
17
{
18
if
(DoEvery(_delay, _lastUpdate)) {
19
if
(
AnalogInputButton::on
() != _state) {
20
_counter++;
21
if
(_counter > _threshold) {
22
setState
(!_state);
23
}
24
}
else
if
(_counter > 0) {
25
_counter = 0;
26
}
27
}
28
}
29
30
// over-rides DigitalInputButton::on
31
bool
DebouncedAnalogButton::on
()
32
{
33
return
_state;
34
}
35
AnalogInputButton
Definition:
AnalogInputButton.h:19
AnalogInputButton::begin
void begin()
Definition:
AnalogInputButton.cpp:11
DebouncedAnalogButton::on
bool on()
Definition:
DebouncedAnalogButton.cpp:31
DebouncedAnalogButton::DebouncedAnalogButton
DebouncedAnalogButton(const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512)
Definition:
DebouncedAnalogButton.cpp:5
AbstractButton::begin
virtual void begin()
Definition:
AbstractButton.h:23
DebouncedAnalogButton::update
void update()
Definition:
DebouncedAnalogButton.cpp:16
AbstractDebouncedButton::setState
void setState(bool newState)
Definition:
AbstractDebouncedButton.cpp:58
AnalogInputButton::on
bool on()
Definition:
AnalogInputButton.cpp:16
Generated by
1.8.15