Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
ButtonReader.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include "ButtonReader.h"
3
4ButtonReader::ButtonReader(uint8_t pin_btn, const VoltLadder *voltLadder) : voltLadder(*voltLadder), pin_btn(pin_btn) {}
5
7 Buttons state = voltLadder.voltageToButton(analogRead(pin_btn));
8 if (state != lastState) {
9 lastState = state;
10 pressedSince = micros();
11 }
12}
13
15 return lastState;
16}
17
19 return micros() - pressedSince;
20}
Buttons
Possible button values.
Definition Buttons.h:5
uint8_t pin_btn
Pin corresponding to the keypad.
uint32_t getPressedFor() const
Get the duration the key has been pressed. This can be used for debouncing using a stable interval.
Buttons isPressed() const
Get the button state.
ButtonReader(uint8_t pin_btn, const VoltLadder *voltLadder)
Constructor.
unsigned long pressedSince
Time of the start of the keypress (in micros)
void sample()
Sample the button signal. Call this in the main loop.
const VoltLadder & voltLadder
Reference to a voltLadder instance.
Buttons lastState
Last sampled state of the keypad.
VoltLadder voltLadder
Definition main.cpp:33