All Projects → r89m → Button

r89m / Button

Licence: other
An Arduino compatible library to make working with user input easier

Projects that are alternatives of or similar to Button

Arduino Homekit Esp8266
Native Apple HomeKit accessory implementation for the ESP8266 Arduino core.
Stars: ✭ 545 (+1918.52%)
Mutual labels:  arduino, arduino-library
Tembooforesp8266
Arduino Library of Temboo modified for ESP8266
Stars: ✭ 5 (-81.48%)
Mutual labels:  arduino, arduino-library
Arduinojson
📟 JSON library for Arduino and embedded C++. Simple and efficient.
Stars: ✭ 5,456 (+20107.41%)
Mutual labels:  arduino, arduino-library
Watchy
Watchy - An Open Source E-Ink Smartwatch
Stars: ✭ 469 (+1637.04%)
Mutual labels:  arduino, arduino-library
Grove bme280
Stars: ✭ 18 (-33.33%)
Mutual labels:  arduino, arduino-library
Esp32 Ble Keyboard
Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 533 (+1874.07%)
Mutual labels:  arduino, arduino-library
Arduinothread
⏳ A simple way to run Threads on Arduino
Stars: ✭ 760 (+2714.81%)
Mutual labels:  arduino, arduino-library
Arduino Foc
Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
Stars: ✭ 387 (+1333.33%)
Mutual labels:  arduino, arduino-library
Easyntpclient
Library to read time from Network Time Protocol (NTP) servers.
Stars: ✭ 20 (-25.93%)
Mutual labels:  arduino, arduino-library
Dimswitch
Arduino library to control dimmable ballasts for fluorescent light tubes
Stars: ✭ 17 (-37.04%)
Mutual labels:  arduino, arduino-library
Remotedebug
Library for Arduino to debug projects over WiFi, with web app or telnet, with print commands like Serial Monitor
Stars: ✭ 467 (+1629.63%)
Mutual labels:  arduino, arduino-library
Ewma
Exponentially Weighted Moving Average Filter
Stars: ✭ 21 (-22.22%)
Mutual labels:  arduino, arduino-library
Awesome Arduino
A curated list of awesome Arduino hardwares, libraries and softwares with update script
Stars: ✭ 446 (+1551.85%)
Mutual labels:  arduino, arduino-library
Guislice
GUIslice drag & drop embedded GUI in C for touchscreen TFT on Arduino, Raspberry Pi, ARM, ESP8266 / ESP32 / M5stack using Adafruit-GFX / TFT_eSPI / UTFT / SDL
Stars: ✭ 534 (+1877.78%)
Mutual labels:  arduino, arduino-library
Onebutton
An Arduino library for using a single button for multiple purpose input.
Stars: ✭ 418 (+1448.15%)
Mutual labels:  arduino, arduino-library
Brutal
Payload for teensy like a rubber ducky but the syntax is different. this Human interfaes device ( HID attacks ). Penetration With Teensy . Brutal is a toolkit to quickly create various payload,powershell attack , virus attack and launch listener for a Human Interface Device ( Payload Teensy )
Stars: ✭ 678 (+2411.11%)
Mutual labels:  arduino, arduino-library
Qrcode
QR code generation library in C, optimized for low-power devices, such as Arduino.
Stars: ✭ 351 (+1200%)
Mutual labels:  arduino, arduino-library
Control Surface
Arduino library for creating MIDI controllers and other MIDI devices.
Stars: ✭ 377 (+1296.3%)
Mutual labels:  arduino, arduino-library
Esp8266 Weather Station
ESP8266 Weather Station library supporting OpenWeatherMap, Aeris and other sources
Stars: ✭ 822 (+2944.44%)
Mutual labels:  arduino, arduino-library
Ntc thermistor
[For Arduino and STM32] Library for working with a NTC thermistor.
Stars: ✭ 19 (-29.63%)
Mutual labels:  arduino, arduino-library

r89m Buttons

This library makes working with buttons easy.

Easily handle button events such as onPress, onHold, onHoldRepeat and onRelease. The same callback functions can be used with multiple buttons, helping to keep your code cleaner and more manageable.

Swap button types whenever you want - there's currently 3 supported types - PushButton, CapacitiveButton and MPR121Button but it is easy to create your own.

Examples

Here's some basic examples to show you just how easy using this library is!

#include <Button.h>
#include <ButtonEventCallback.h>
#include <BasicButton.h>

// Create an instance of BasicButton reading digital pin 5
BasicButton button = BasicButton(5);

void setup(){

    // When the button is first pressed, call the function onButtonPressed
    button.onPress(onButtonPressed);
}

void loop(){
    // Check the state of the button
    button.update();
}

void onButtonPressed(Button& btn){

    // The button was pressed - do something!
}
#include <Button.h>
#include <ButtonEventCallback.h>
#include <BasicButton.h>

// Create an instance of BasicButton reading digital pin 5
BasicButton button = BasicButton(5);

void setup(){

    // Open up the serial port so that we can write to it
    Serial.begin(9600);

    // When the button is first pressed, call the function onButtonPressed
    button.onPress(onButtonPressed);
    // Once the button has been held for 1 second (1000ms) call onButtonHeld. Call it again every 0.5s (500ms) until it is let go
    button.onHoldRepeat(1000, 500, onButtonHeld);
    // When the button is released, call onButtonReleased
    button.onRelease(onButtonReleased);
}

void loop(){
    // Check the state of the button
    button.update();
}

// btn is a reference to the button that fired the event. That means you can use the same event handler for many buttons
void onButtonPressed(Button& btn){

    Serial.println("button pressed");
}

// duration reports back how long it has been since the button was originally pressed.
// repeatCount tells us how many times this function has been called by this button.
void onButtonHeld(Button& btn, uint16_t duration, uint16_t repeatCount){

    Serial.print("button has been held for ");
    Serial.print(duration);
    Serial.print(" ms; this event has been fired ");
    Serial.print(repeatCount);
    Serial.println(" times");
}

// duration reports back the total time that the button was held down
void onButtonReleased(Button& btn, uint16_t duration){

    Serial.print("button released after ");
    Serial.print(duration);
    Serial.println(" ms");
}

Built-in Button Types

PushButton

A simple push button debounced using the Bounce library

Check out the examples!

CapacitiveButton

A capacitive touch button utilising the CapSense library

Check out the examples!

MPR121Button

A capacitive touch button utilising the MPR121 touch switch IC

Check out the examples!

BasicButton (not recommended!)

A simple button using digitalRead() to determine the state of the button. Does not perform any kind of debouncing, so false positives and multiple calls are likely. Use PushButton instead for a simple button.

This is only included so that you can get an example up-and-running quickly without needing any other dependencies.

Methods

boolean update()

Update the button state - this will call any callbacks that are necessary. Returns true if the state changes.

boolean is(Button& btn)

Return whether or not the button is the same as the btn passed

boolean isPressed()

Return whether or not the button is currently pressed.

Callbacks

CallbackAttachedResponse onPress(onPressCallbackFunction)

onPressCallbackFunction is a function which will be called as soon as the button is pressed. It must be defined with the parameters shown below

void callThisFunctionOnPress(Button& btn){
  // btn is a reference to the button that was pressed.
}

CallbackAttachedResponse onRelease

There are 3 variations of onRelease:

CallbackAttachedResponse onRelease(onReleaseCallbackFunction)

onReleaseCallbackFunction is a function which is called when the button is released. It must be defined with the parameters shown below

void callThisFunctionOnRelease(Button& btn, uint_16t duration){
  // btn is a reference to the button that was pressed
  // duration is how long the button was pressed for
}

CallbackAttachedResponse onRelease(uint_16t wait, onReleaseCallbackFunction)

As above, plus:

wait if the button is held for at-least waitms onReleaseCallbackFunction will be called.

CallbackAttachedResponse onRelease(uint_16t wait, uint_16t max_wait, onReleaseCallbackFunction)

As above, plus:

max_wait if the button is held for more than max_waitms onReleaseCallbackFunction will not be called.

CallbackAttachedResponse onHold(uint_16t duration, onHoldCallbackFunction)

duration how long the button must be held before onHoldCallbackFunction is called. onHoldCallbackFunction is a function which is called when the button is held. It must be defined with the parameters shown below

void callThisFuntionOnHold(Button& btn, uint_16t duration){
  // btn is a reference to the button that was held
  // duration is how long the button was held for
}

CallbackAttachedResponse onHoldAndRepeat(uint_16t duration, uint_16t repeat_every, onHoldAndRepeatCallbackFunction)

duration how long the button must be held before onHoldAndRepeatCallbackFunction is called. repeat_every how long to wait before onHoldAndRepeatCallbackFunction is called repeatedly. onHoldAndRepeatCallbackFunction is a function which is called repeatedly when the button is held. It must be defined with the parameters shown below

void callThisFunctionOnHoldAndRepeat(Button& btn, uint16_t duration, uint8_t repeat_count){
  // btn is a reference to the button that was held
  // duration is how long the button has been held for
  // repeat_count is the number of times the callback has been called
}

Enums

CallbackAttachedResponse

attSuccessful returned when a callback has successfully been attached

attNoMoreRoom returned when a callback could not be attached because there is not enough room. Check MAX_CALLBACKS_PER_BUTTON.

Constants

MAX_CALLBACKS_PER_BUTTON (default=3)

Defines the maximum number of callbacks per button. Increasing this number will allow more callbacks but will use marginally more memory and processing power. This can be changed on a sketch by sketch basis, simply define #MAX_CALLBACKS_PER_BUTTON before your #includes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].