GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ARDUnia/ARDUniaButton: A lightweight, non-blocking Arduino library for reliable button input, debounce, click detection, long press, multi-click, and repeat events.

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
src
src
 
 
test/host
test/host
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
keywords.txt
keywords.txt
 
 
library.properties
library.properties
 
 

Repository files navigation

ARDUniaButton

CI Latest Release License: MIT Platform: Arduino Language: C++

A lightweight, non-blocking Arduino library for physical push buttons.

ARDUniaButton provides a simple polling API and optional callbacks for debounced press/release events, single/double/multi-click detection, long presses, and repeat-while-held behavior. It uses millis(), requires no third-party dependencies, and avoids dynamic memory allocation.

Features

  • Non-blocking debounce using millis()
  • Default wiring: digital pin → button → GND, using INPUT_PULLUP
  • Active-LOW and Active-HIGH logic
  • INPUT, INPUT_PULLUP, and INPUT_PULLDOWN when the selected Arduino core defines it
  • Press and release events
  • Single, double, and multi-click detection
  • Long-press detection and held-state reporting
  • Configurable repeat delay and interval while held
  • Polling and callback APIs
  • Independent one-shot event flags
  • Safe elapsed-time comparisons across millis() rollover
  • No third-party dependencies or dynamic allocation

Installation

Arduino Library Manager

Once ARDUniaButton is accepted into the Arduino Library Manager index, open Tools → Manage Libraries… (or Sketch → Include Library → Manage Libraries… in Arduino IDE 1.x), search for ARDUniaButton, and install it.

Install from ZIP

Until the Library Manager listing is available, download the ZIP from the GitHub repository, then select Sketch → Include Library → Add .ZIP Library… in Arduino IDE.

Wiring

The default configuration expects a button connected between a digital GPIO pin and GND:

Arduino GPIO ----[ BUTTON ]---- GND

The internal pull-up is enabled by default, so no external pull-up resistor is required for this wiring.

Basic usage

#include <ARDUniaButton.h>

ARDUniaButton button(7); // INPUT_PULLUP, active LOW

void setup() {
  Serial.begin(115200);
  if (!button.begin()) {
    Serial.println("Invalid button configuration");
  }
}

void loop() {
  button.update();

  if (button.wasPressed()) Serial.println("Pressed");
  if (button.wasReleased()) Serial.println("Released");
  if (button.wasClicked()) Serial.println("Click");
  if (button.wasDoubleClicked()) Serial.println("Double click");
  if (button.wasMultiClicked()) {
    Serial.print("Multi click: ");
    Serial.println(button.clickCount());
  }
  if (button.wasLongPressed()) Serial.println("Long press");
  if (button.wasRepeated()) Serial.println("Repeat");
}

Call update() regularly from loop(). The library does not create its own timer or interrupt.

Default timing

Setting Default
Debounce 30 ms
Long press 1000 ms
Double-click window 400 ms
Repeat initial delay 500 ms
Repeat interval 100 ms

Configure timings with:

button.setDebounce(30);
button.setLongPressTime(1000);
button.setDoubleClickTime(400);
button.setRepeat(500, 100);

The setters return true when a value is accepted and false when it is outside the supported range.

Event semantics

  • wasPressed() and wasReleased() report debounced transitions.
  • wasLongPressed() fires once when the long-press threshold is reached.
  • wasRepeated() fires at the configured repeat interval after the repeat delay.
  • A long press is not counted as a click.
  • Click events are delayed until the double-click window expires so a second press can be detected.
  • The wasXxx() event flags are independent and remain available until the next call to update().
  • event() returns the last event generated by the most recent update(). If several events occur during one update, use the individual wasXxx() flags to check them all.
  • clickCount() returns the count for a multi-click event; it is meaningful when wasMultiClicked() is true.

Callback API

Register callbacks before or after begin():

button.onClick([]() {
  Serial.println("Click");
});

button.onLongPress([]() {
  Serial.println("Long press");
});

button.onRepeat([](uint8_t count) {
  Serial.println(count);
});

Supported callbacks are onPress(), onRelease(), onClick(), onDoubleClick(), onMultiClick(), onLongPress(), and onRepeat().

Active-HIGH input

Active-HIGH input can be configured when the hardware provides an appropriate pull-down or external resistor:

ARDUniaButton button(7, INPUT, false);

The classic Arduino AVR core used by Arduino UNO does not define INPUT_PULLDOWN. ARDUniaButton only references that symbol when the selected core defines it.

Examples

  • BasicUsage — polling API and the main events
  • Callbacks — callback-based event handling
  • VolumeControl — repeat behavior for up/down controls

Compatibility

The library uses standard Arduino APIs and has no third-party dependencies. It is intended for Arduino-compatible cores that provide Arduino.h, millis(), pinMode(), and digitalRead(). Compatibility claims should be verified against the specific board core and version in use.

Tests

The host-side test suite simulates Arduino GPIO and time, including basic click, double-click, long-press, and repeat behavior. Run it from the repository root:

sh test/host/run_test.sh

GitHub Actions runs the host tests and checks library metadata with Arduino Lint.

Project

ARDUniaButton is an open-source project from ARDUnia, created by Hamidreza Milaninia.

  • ARDUnia: https://ardunia.ir
  • Author: https://hrmnia.com
  • Repository: https://github.com/ARDUnia/ARDUniaButton

License

MIT. See LICENSE.

About

A lightweight, non-blocking Arduino library for reliable button input, debounce, click detection, long press, multi-click, and repeat events.

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.