AwesomeStudioPedal
A programmable, multi-profile foot controller for DAWs, score readers, and studio automation
Loading...
Searching...
No Matches
nrf52840/src/button.cpp
Go to the documentation of this file.
1#include "button.h"
2#include <Arduino.h>
3
4Button::Button(uint8_t PIN) : PIN(PIN) {}
5
6void Button::setup() { pinMode(PIN, INPUT_PULLUP); }
7
8bool Button::isDebounced(unsigned long now) const
9{
10 return (now - lastDebounceTime) > debounceDelay;
11}
12
13void Button::isr()
14{
15 unsigned long now = millis();
16 if (digitalRead(PIN) == HIGH)
17 {
18 if (awaitingRelease && isDebounced(now))
19 {
20 awaitingRelease = false;
21 lastDebounceTime = now;
22 }
23 return;
24 }
25 if (! awaitingRelease && isDebounced(now))
26 {
27 pressCount++;
28 awaitingRelease = true;
29 lastDebounceTime = now;
30 }
31}
32
33bool Button::event()
34{
35 if (pressCount > 0)
36 {
37 pressCount--;
38 return true;
39 }
40 return false;
41}
42
43void Button::reset()
44{
45 pressCount = 0;
46 awaitingRelease = false;
48}
void setup() override
Configures the GPIO pin as input with pull-up.
volatile bool awaitingRelease
True after press, until pin goes HIGH.
volatile uint8_t pressCount
Incremented by ISR, decremented by event()
Button(uint8_t PIN)
Constructs a Button for the given GPIO pin.
unsigned long lastDebounceTime
Timestamp of last accepted press.
void isr()
ISR entry point — call from an IRAM_ATTR interrupt handler.
unsigned long debounceDelay
Debounce window in milliseconds.
void reset() override
Clears the pressed flag.
bool event() override
Checks for a press event and clears the flag.