/* * button.h — Debounced button with single-tap, double-tap, and hold detection. * * Wiring: connect one leg of the button to the configured pin, the other to GND. * Uses INPUT_PULLUP — no external resistor needed. * * Timing (adjust in button.cpp if needed): * DEBOUNCE_MS — ignores bounces shorter than this (default 50ms) * HOLD_MS — how long to hold before BTN_HOLD fires (default 800ms) * DOUBLE_TAP_MS — window to catch a second tap (default 400ms) * * Note: single taps are confirmed after DOUBLE_TAP_MS of silence so the * code can tell them apart from the start of a double-tap. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include enum ButtonEvent : uint8_t { BTN_NONE, // nothing happened BTN_TAP, // one short press, released, no second press within window BTN_DOUBLE_TAP, // two presses within DOUBLE_TAP_MS of each other BTN_HOLD, // button held longer than HOLD_MS }; // Initialize the button. Call once in setup(). // pin: the Arduino pin the button is wired to (other end to GND). void button_begin(uint8_t pin); // Poll for button events. Call once per loop(). // Returns BTN_NONE most of the time; returns an event exactly once when detected. ButtonEvent button_update();