carb-sync/twinmax/sensors.h

45 lines
823 B
C++

#ifndef _SENSORS_H_DEF_
#define _SENSORS_H_DEF_
#define HOLD_MS_THRESHOLD 2000
// push button non-blocking state
class PushButton {
public:
void setup(const int pin);
bool tap(); // button has been pushed for a short amount of time
bool hold(); // button has been pushed for at least HOLD_MS_THRESHOLD milliseconds
private:
// returns whether the button state changed
bool tick();
// value of millis() when the button is down
unsigned long _pushStart { 0 };
bool _pushed { false };
int _pin { 0 };
};
// potentiometer value
class Potentiometer {
public:
void setup(const int pin);
short range();
private:
int _pin { 0 };
};
// pressure sensors
class Pressure {
public:
void setup(const int pin);
short value();
private:
int _pin { 0 };
};
#endif