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
10
12 if (millis() - previousMillisISR > 250) {
13 currentValue += 1;
15
16 previousMillisISR = millis();
17 }
18}
19
20void ButtonHandler::Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle) {
21 pinMode(pin, INPUT_PULLUP);
22 attachInterrupt(digitalPinToInterrupt(pin), isr, FALLING);
23
27}
28
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;
37 }
38
39 return holdingState;
40}
41
43 return currentValue;
44}
Declares the ButtonHandler class for managing button input and state.
static uint16_t holdingToggle
Time threshold for detecting holding behavior in milliseconds.
static long previousMillisISR
Tracks the last interrupt service routine (ISR) trigger time in milliseconds.
static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle)
Initializes the ButtonHandler with specified parameters.
static long previousMillisHold
Tracks the last hold event time in milliseconds.
static void isr()
Interrupt service routine (ISR) for handling button presses.
static bool GetHoldingState()
Retrieves the holding state of the button.
static uint8_t GetValue()
Retrieves the current value of the button.
static uint8_t pin
The pin number associated with the button.
static uint8_t maxValue
The maximum value for the button press count.
static bool holdingState
Indicates whether the button is in a holding state.
static uint8_t currentValue
The current value of the button (e.g., press count).