ProtoTracer
1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ButtonHandler.cpp
Go to the documentation of this file.
1
#include "
ButtonHandler.h
"
2
3
long
ButtonHandler::previousMillisISR
;
4
long
ButtonHandler::previousMillisHold
;
5
uint16_t
ButtonHandler::holdingToggle
;
6
uint8_t
ButtonHandler::currentValue
;
7
uint8_t
ButtonHandler::maxValue
;
8
uint8_t
ButtonHandler::pin
;
9
bool
ButtonHandler::holdingState
;
10
11
void
ButtonHandler::isr
() {
12
if
(millis() -
previousMillisISR
> 250) {
13
currentValue
+= 1;
14
if
(
currentValue
>
maxValue
)
currentValue
= 0;
15
16
previousMillisISR
= millis();
17
}
18
}
19
20
void
ButtonHandler::Initialize
(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle) {
21
pinMode(
pin
, INPUT_PULLUP);
22
attachInterrupt(digitalPinToInterrupt(
pin
),
isr
, FALLING);
23
24
ButtonHandler::maxValue
=
maxValue
;
25
ButtonHandler::pin
=
pin
;
26
ButtonHandler::holdingToggle
=
holdingToggle
;
27
}
28
29
bool
ButtonHandler::GetHoldingState
() {
30
long
currentTime = millis();
31
32
if
(digitalRead(
pin
)) {
// Pin is on, button not pressed
33
previousMillisHold
= currentTime;
34
}
else
if
(currentTime -
previousMillisHold
>
holdingToggle
) {
35
previousMillisHold
= currentTime;
36
holdingState
= !
holdingState
;
37
}
38
39
return
holdingState
;
40
}
41
42
uint8_t
ButtonHandler::GetValue
() {
43
return
currentValue
;
44
}
ButtonHandler.h
Declares the ButtonHandler class for managing button input and state.
ButtonHandler::holdingToggle
static uint16_t holdingToggle
Time threshold for detecting holding behavior in milliseconds.
Definition
ButtonHandler.h:27
ButtonHandler::previousMillisISR
static long previousMillisISR
Tracks the last interrupt service routine (ISR) trigger time in milliseconds.
Definition
ButtonHandler.h:25
ButtonHandler::Initialize
static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle)
Initializes the ButtonHandler with specified parameters.
Definition
ButtonHandler.cpp:20
ButtonHandler::previousMillisHold
static long previousMillisHold
Tracks the last hold event time in milliseconds.
Definition
ButtonHandler.h:26
ButtonHandler::isr
static void isr()
Interrupt service routine (ISR) for handling button presses.
Definition
ButtonHandler.cpp:11
ButtonHandler::GetHoldingState
static bool GetHoldingState()
Retrieves the holding state of the button.
Definition
ButtonHandler.cpp:29
ButtonHandler::GetValue
static uint8_t GetValue()
Retrieves the current value of the button.
Definition
ButtonHandler.cpp:42
ButtonHandler::pin
static uint8_t pin
The pin number associated with the button.
Definition
ButtonHandler.h:30
ButtonHandler::maxValue
static uint8_t maxValue
The maximum value for the button press count.
Definition
ButtonHandler.h:29
ButtonHandler::holdingState
static bool holdingState
Indicates whether the button is in a holding state.
Definition
ButtonHandler.h:31
ButtonHandler::currentValue
static uint8_t currentValue
The current value of the button (e.g., press count).
Definition
ButtonHandler.h:28
lib
ProtoTracer
ExternalDevices
InputDevices
ButtonHandler.cpp
Generated by
1.9.8