Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
button.hpp File Reference

Button component: a debounced digital input with edges and a held time. More...

Detailed Description

Button component: a debounced digital input with edges and a held time.

Button takes logical GPIO readings (true = pressed; Gpio::read() already applies active-low) and the time since the reading before, and gives the debounced state, its edges and how long the button has been held.

Times are ticks of the clock that drives it, the control clock's elapsed ticks as a scheduler subscriber receives them. It holds no rate and counts no calls: a duration in milliseconds becomes ticks at the edge, through the clock.

sbl::control::input::Button btn{{Clock::ticks_from_ms(5)}};
// or, on a generated Board: board.button1.set_debounce_ticks(Clock::ticks_from_ms(5));
btn.update(gpio_reading, elapsed_ticks);
if (btn.just_pressed()) { ... }
if (btn.held_ticks() > Clock::ticks_from_ms(500)) { ... } // a long press
Debounced button with edge detection and held-time tracking.
Definition button.hpp:42
void update(bool logical_state, uint32_t elapsed_ticks)
Feed a reading and the time since the one before.
Definition button.hpp:65

Definition in file button.hpp.

#include <cstdint>

Go to the source code of this file.

Classes

struct  sbl::control::input::ButtonConfig
 Button construction settings. More...
 
class  sbl::control::input::Button
 Debounced button with edge detection and held-time tracking. More...
 

Namespaces

namespace  sbl
 Root namespace for all Sound Byte Libs code.
 
namespace  sbl::control
 The control stack: scheduler, event queue, merge, CC mapping, calibration.
 
namespace  sbl::control::input
 Inputs: debounce, decoding, smoothing and scaling of raw samples.