Files
Amirine_Cosplay_Lights/arduino/cosplay_lights/button.h
T
bgrolleman 11eb2584ef Initial commit — Amirine Cosplay Lights
Arduino Uno + WS2812B LED strip controller with a text-based lightshow
system. Shows are defined as .txt files (hex color + fade duration per step),
converted to PROGMEM headers by convert_all.py, and navigated at runtime
via a debounced button (tap/double-tap/hold). BSD 2-Clause license.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 10:16:56 +02:00

35 lines
1.3 KiB
C

/*
* 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 <stdint.h>
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();