Arduino library · Input

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 nameGyverButton
AuthorAlexGyver
Include#include <GyverButton.h>
Boardsevery board Mokxi compiles for
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesPushbutton

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.

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.

sketch.ino · Arduino Uno R3
#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

Open it in the editor, wired and ready to run

Try GyverButton without installing anything

Open the example, change the sketch, and keep your version in a free account.