AwesomeStudioPedal
A programmable, multi-profile foot controller for DAWs, score readers, and studio automation
Loading...
Searching...
No Matches
Button Class Reference

ESP32 interrupt-driven button with debouncing. More...

#include <button.h>

Inheritance diagram for Button:
IButton IButton

Public Member Functions

 Button (uint8_t PIN)
 Constructs a Button for the given GPIO pin.
 
void setup () override
 Configures the GPIO pin as input with pull-up.
 
void isr ()
 ISR entry point — call from an IRAM_ATTR interrupt handler.
 
bool event () override
 Checks for a press event and clears the flag.
 
void reset () override
 Clears the pressed flag.
 
 Button (uint8_t PIN)
 Constructs a Button for the given pin.
 
void setup () override
 Configures the pin as input with pull-up.
 
void isr ()
 Interrupt service routine — call from a CHANGE ISR.
 
bool event () override
 Consumes and returns a pending press event.
 
void reset () override
 Clears any pending press event.
 
- Public Member Functions inherited from IButton
virtual ~IButton ()=default
 

Public Attributes

volatile uint8_t pressCount = 0
 Incremented by ISR, decremented by event()
 
volatile bool awaitingRelease = false
 True after press, until pin goes HIGH.
 
unsigned long lastDebounceTime = 0
 Timestamp of last accepted press.
 
unsigned long debounceDelay = 100
 Debounce window in milliseconds.
 

Detailed Description

ESP32 interrupt-driven button with debouncing.

nRF52840-specific implementation of IButton interface

Implements IButton using hardware GPIO interrupts and millis()-based debouncing. isr() must be called from an IRAM_ATTR interrupt handler attached with attachInterrupt().

Interrupt-driven button with software debouncing. Attach isr() to a CHANGE interrupt on the button pin. digitalRead() is used inside isr() to filter release edges.

Definition at line 13 of file esp32/include/button.h.

Constructor & Destructor Documentation

◆ Button() [1/2]

Button::Button ( uint8_t  PIN)
explicit

Constructs a Button for the given GPIO pin.

Parameters
PINGPIO pin number

Definition at line 7 of file esp32/src/button.cpp.

◆ Button() [2/2]

Button::Button ( uint8_t  PIN)
explicit

Constructs a Button for the given pin.

Parameters
PINGPIO pin number

Member Function Documentation

◆ event() [1/2]

bool Button::event ( )
overridevirtual

Checks for a press event and clears the flag.

Returns
true if pressed since last call, false otherwise

Implements IButton.

Definition at line 40 of file esp32/src/button.cpp.

◆ event() [2/2]

bool Button::event ( )
overridevirtual

Consumes and returns a pending press event.

Returns
true if a press event was pending

Implements IButton.

◆ isr() [1/2]

void Button::isr ( )

ISR entry point — call from an IRAM_ATTR interrupt handler.

Applies debouncing and sets the pressed flag if a valid press is detected.

Definition at line 20 of file esp32/src/button.cpp.

◆ isr() [2/2]

void Button::isr ( )

Interrupt service routine — call from a CHANGE ISR.

Filters release edges via digitalRead and applies debouncing.

◆ reset() [1/2]

void Button::reset ( )
overridevirtual

Clears the pressed flag.

Call before attachInterrupt() to discard any stale press.

Implements IButton.

Definition at line 50 of file esp32/src/button.cpp.

◆ reset() [2/2]

void Button::reset ( )
overridevirtual

Clears any pending press event.

Implements IButton.

◆ setup() [1/2]

void Button::setup ( )
overridevirtual

Configures the GPIO pin as input with pull-up.

Must be called before attachInterrupt().

Implements IButton.

Definition at line 9 of file esp32/src/button.cpp.

◆ setup() [2/2]

void Button::setup ( )
overridevirtual

Configures the pin as input with pull-up.

Implements IButton.

Member Data Documentation

◆ awaitingRelease

volatile bool Button::awaitingRelease = false

True after press, until pin goes HIGH.

Definition at line 25 of file esp32/include/button.h.

◆ debounceDelay

unsigned long Button::debounceDelay = 100

Debounce window in milliseconds.

Minimum ms between accepted events.

Definition at line 27 of file esp32/include/button.h.

◆ lastDebounceTime

unsigned long Button::lastDebounceTime = 0

Timestamp of last accepted press.

Timestamp of last accepted ISR.

Definition at line 26 of file esp32/include/button.h.

◆ pressCount

volatile uint8_t Button::pressCount = 0

Incremented by ISR, decremented by event()

Incremented by ISR; decremented by event()

Definition at line 24 of file esp32/include/button.h.


The documentation for this class was generated from the following files: