HotButton: an example that runs
Yes. You can use the HotButton library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Pushbutton). The example below, "A click, a short-long pattern and a one-second hold", runs on the Arduino Uno R3.
Built in on Mokxi: #include <HotButton.h> and it builds, with nothing to install. Free, and no account needed.
What HotButton does
Update(), then isSingleClick() to isQuadrupleClick(), pressedFor(ms) and event(SHORT, LONG) for patterns of presses. That is what HotButton, by Rop Gonggrijp, covers. The sketch below uses it on the Arduino Uno: “A click, a short-long pattern and a one-second hold”.
Rop Gonggrijp's HotButton library (0.1.1): clicks, long presses and whole patterns of presses from one button.
Use the pushbutton part between the pin and GND with the pull-up on (the second argument true), or between the pin and 5 V with a pull-down and active HIGH.
The calls follow release 0.1.1 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | HotButton |
|---|---|
| Author | Rop Gonggrijp |
| Include | #include <HotButton.h> |
| Boards | every board Mokxi compiles for |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Pushbutton |
Install it
It builds on every board Mokxi compiles for.
In Mokxi it is built in: #include <HotButton.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "HotButton" by Rop Gonggrijp from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add HotButton to lib_deps in PlatformIO. Mokxi follows the calls of release 0.1.1, so a sketch written here builds there too.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- ATtiny85
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
HotButton myButton(2, true)
Makes myButton, the HotButton object the calls below are made on.
myButton.update()
Updates it.
myButton.isSingleClick()
Returns true or false for "is single click".
myButton.isDoubleClick()
Returns true or false for "is double click".
Example: A click, a short-long pattern and a one-second hold
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <HotButton.h>
HotButton myButton(2, true); // pull-up on: pressed is LOW
void setup() {
Serial.begin(115200);
Serial.println("ready");
}
void loop() {
myButton.update();
if (myButton.isSingleClick()) Serial.println("The button was clicked.");
if (myButton.isDoubleClick()) Serial.println("The button was double-clicked.");
if (myButton.event(SHORT, LONG)) Serial.println("short, then long");
if (myButton.pressedFor(1000)) Serial.println("held for a second");
}Wiring
- Arduino Uno R3 2 to Pushbutton 1a
- Arduino Uno R3 GND to Pushbutton 2a
Try HotButton without installing anything
Open the example, change the sketch, and keep your version in a free account.