GyverButton: an example that runs
Yes. You can use the GyverButton library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Pushbutton). The example below, "Single, double and held on one button", runs on the Arduino Uno R3.
Built in on Mokxi: #include <GyverButton.h> and it builds, with nothing to install. Free, and no account needed.
What GyverButton does
GButton: tick(), then isClick(), isSingle(), isDouble(), isHolded(), getClicks() and isStep() for a held button. That is what GyverButton, by AlexGyver, covers. The sketch below uses it on the Arduino Uno: “Single, double and held on one button”.
AlexGyver's GyverButton library (3.8): presses, holds, clicks counted in a series, and a step timer for a held button.
Use the pushbutton part between the pin and GND (HIGH_PULL, the default, turns the pin's pull-up on) or between the pin and 5 V with a pull-down (LOW_PULL). The defaults are upstream's: 80 ms of debounce, 500 ms held for a hold, 300 ms between the clicks of a series and 400 ms between steps.
The calls follow release 3.8 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 | GyverButton |
|---|---|
| Author | AlexGyver |
| Include | #include <GyverButton.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 <GyverButton.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "GyverButton" by AlexGyver from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add GyverButton to lib_deps in PlatformIO. Mokxi follows the calls of release 3.8, so a sketch written here builds there too.
What to know in the simulator: The analog keyboard class is not here.
- 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.
GButton butt1(2)
Makes butt1, the GButton object the calls below are made on.
butt1.setDebounce(50)
Sets the debounce to the value you pass in. Arguments: debounce.
butt1.setTimeout(500)
Sets the timeout to the value you pass in. Arguments: timeout.
butt1.setClickTimeout(300)
Sets the click timeout to the value you pass in. Arguments: timeout.
butt1.isSingle()
Returns true or false for "is single".
butt1.isDouble()
Returns true or false for "is double".
butt1.isHolded()
Returns true or false for "is holded".
Example: Single, double and held on one button
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include "GyverButton.h"
GButton butt1(2); // pin --- button --- GND, the pin's pull-up on
void setup() {
Serial.begin(9600);
butt1.setDebounce(50);
butt1.setTimeout(500);
butt1.setClickTimeout(300);
Serial.println("ready");
}
void loop() {
butt1.tick();
if (butt1.isSingle()) Serial.println("Single");
if (butt1.isDouble()) Serial.println("Double");
if (butt1.isHolded()) Serial.println("Holded");
}Wiring
- Arduino Uno R3 2 to Pushbutton 1a
- Arduino Uno R3 GND to Pushbutton 2a
Try GyverButton without installing anything
Open the example, change the sketch, and keep your version in a free account.