dumheter / button

Simple software debouncing button library for arduino.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

button

Simple software debouncing button library for Arduino.

Usage

To use the library drop the folder inside your library folder in arduino. If you don't know where that folder resides, google "Arduino library folder". Then add #include <button.hpp> at the top of your Arduino file.

Or grab the two files button.cpp & button.hpp and put with your .ino file. then #include "button.hpp" and you are ready to go!

Read button.hpp to learn how to use this library, or see example below or in the exmaples folder.

Example

Read example code below, or better yet: Read the button.hpp file.

#include "button.hpp"


//Here we initialize our button on pin 2
Button button(2);


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


void loop () {
  //static makese it set state = false once only.
  static bool state = false;

  if (state != button.read()) {
    state = !state;

    Serial.print("Button state changed to: ");
    Serial.println(state);
  }
}

Wiring

How do you wire the button? See this picture: Image of Wiring

Disclaimer

I have only tested this library with an ESP8266 and not with an Arduino device.

About

Simple software debouncing button library for arduino.

License:MIT License


Languages

Language:C++ 100.0%