Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
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 
12 {
13  // analog inputs don't need to have their mode set explicitly
14 }
15 
17 {
18  if (_pullup) {
19  return (uint16_t)analogRead(_pin) <= _analogThreshold;
20  } else {
21  return (uint16_t)analogRead(_pin) > _analogThreshold;
22  }
23 }
24 
AnalogInputButton(const uint8_t pin, const bool pullup=true, const uint16_t analogThreshold=512)