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
4
ButtonReader::ButtonReader
(uint8_t pin_btn,
const
VoltLadder *
voltLadder
) :
voltLadder
(*
voltLadder
), pin_btn(pin_btn) {}
5
6
void
ButtonReader::sample
() {
7
Buttons
state =
voltLadder
.voltageToButton(analogRead(
pin_btn
));
8
if
(state !=
lastState
) {
9
lastState
= state;
10
pressedSince
= micros();
11
}
12
}
13
14
Buttons
ButtonReader::isPressed
()
const
{
15
return
lastState
;
16
}
17
18
uint32_t
ButtonReader::getPressedFor
()
const
{
19
return
micros() -
pressedSince
;
20
}
ButtonReader.h
Buttons
Buttons
Possible button values.
Definition
Buttons.h:5
ButtonReader::pin_btn
uint8_t pin_btn
Pin corresponding to the keypad.
Definition
ButtonReader.h:13
ButtonReader::getPressedFor
uint32_t getPressedFor() const
Get the duration the key has been pressed. This can be used for debouncing using a stable interval.
Definition
ButtonReader.cpp:18
ButtonReader::isPressed
Buttons isPressed() const
Get the button state.
Definition
ButtonReader.cpp:14
ButtonReader::ButtonReader
ButtonReader(uint8_t pin_btn, const VoltLadder *voltLadder)
Constructor.
Definition
ButtonReader.cpp:4
ButtonReader::pressedSince
unsigned long pressedSince
Time of the start of the keypress (in micros)
Definition
ButtonReader.h:16
ButtonReader::sample
void sample()
Sample the button signal. Call this in the main loop.
Definition
ButtonReader.cpp:6
ButtonReader::voltLadder
const VoltLadder & voltLadder
Reference to a voltLadder instance.
Definition
ButtonReader.h:12
ButtonReader::lastState
Buttons lastState
Last sampled state of the keypad.
Definition
ButtonReader.h:15
voltLadder
VoltLadder voltLadder
Definition
main.cpp:33
src
input
ButtonReader.cpp
Generated by
1.12.0