Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
src
AnalogInputButton.cpp
1
#include <Arduino.h>
2
#include "AnalogInputButton.h"
3
4
AnalogInputButton::AnalogInputButton
(
const
uint8_t pin,
const
bool
pullup,
const
uint16_t analogThreshold) :
5
_pin(pin),
6
_pullup(pullup),
7
_analogThreshold(analogThreshold)
8
{
9
}
10
11
void
AnalogInputButton::begin
()
12
{
13
// analog inputs don't need to have their mode set explicitly
14
}
15
16
bool
AnalogInputButton::on
()
17
{
18
if
(_pullup) {
19
return
(uint16_t)analogRead(_pin) <= _analogThreshold;
20
}
else
{
21
return
(uint16_t)analogRead(_pin) > _analogThreshold;
22
}
23
}
24
AnalogInputButton::begin
void begin()
Definition:
AnalogInputButton.cpp:11
AnalogInputButton::on
bool on()
Definition:
AnalogInputButton.cpp:16
AnalogInputButton::AnalogInputButton
AnalogInputButton(const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512)
Definition:
AnalogInputButton.cpp:4
Generated by
1.8.15