/*
LC_base Tools mechButton demo
https://github.com/leftCoast/LC_baseTools/tree/master
*/
#include <mechButton.h>
const int BUTTON_PIN = 2; // button pin, other side of button to ground
const int LED_PIN = 13; // usual pin number for built in LED.
mechButton button1(BUTTON_PIN); // create mechButton object
// this function is called when the button changes state.
void btnCallback(void) {
static bool ledState = false;
bool state = button1.getState();
Serial.print("Button just became "); // We just saw the button change state.
if (state) { // If the button state is now high.
Serial.println("true!"); // Tell the user.
} else { // Else it just bacame low. (Grounded, pushed)
Serial.println("false!"); // Tell user.
ledState = !ledState; // toggle ledState
} //
digitalWrite(LED_PIN, ledState); // write the new ledState.
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
button1.setCallback(btnCallback); // Set up our callback. (Also calls hookup() for idling.)
}
void loop() {
idle();
}