wachidsusilo / Button

A utility for arduino to setup buttons easily. This library needs Timer as it's dependancy. You can find it in my repository.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Button for Arduino

A simple button library for arduino. This library rely on Timer and ArrayList libraries. You can download or clone it from my repository

Example

This library provide easy implementation of onPress, onLongPress, and onReleased event.

#include "Button.h"

Button button(2);

void onPressed() {
    Serial.println("Button pressed");
}

void onLongPressed() {
    Serial.println("Button long pressed");
}

void onReleased() {
    Serial.println("Button released");
}

void setup() {
    Serial.begin(115200);

    //true means INPUT_PULLUP
    button.begin(true);

    //Assign onPressCallback with onPressed() function
    button.onPress(onPressed);

    //Assign onLongPressCallback with onLongPressed() function
    button.onLongPress(onLongPressed);

    //Assign onReleaseCallback with onreleased() function
    button.onRelease(onReleased);
}

void loop() {
    Timer.run();
}

About

A utility for arduino to setup buttons easily. This library needs Timer as it's dependancy. You can find it in my repository.


Languages

Language:C++ 100.0%