////////////////////////////////////////////////////////////////////
// This is a soft on\off power switch
// Graphing Tool: https://dreampuf.github.io/
// INCLUDES ///////////////////////////////////////////////////////
#include "Button2.h" // https://github.com/LennartHennigs/Button2
// DEFINES /////////////////////////////////////////////////////////
#define BUTTON_PIN 13
#define POWER_LED_PIN 12
#define COUNTING_LED_PIN 14
#define SERIAL_BAUD 115200
// VARIABLES /////////////////////////////////////////////////////
Button2 button;
// BUTTON HANDLERS /////////////////////////////////////////////////
// https://github.com/LennartHennigs/Button2/blob/master/src/Button2.h
void button_handler_short(Button2 &button) {
Serial.println("button_handler_short()");
}
void button_handler_long(Button2 &button) {
Serial.println("button_handler_long()");
}
void button_handler_double(Button2 &button) {
Serial.println("button_handler_double()");
}
// SETUP FUNCTIONS ///////////////////////////////////////////////
void setup_button() {
Serial.println("setup_buttons()");
button.begin(BUTTON_PIN, INPUT_PULLUP);
button.setClickHandler(button_handler_short);
button.setLongClickDetectedHandler(button_handler_long);
button.setDoubleClickHandler(button_handler_double);
}
void setup_leds() {
Serial.println("setup_leds()");
pinMode(POWER_LED_PIN, OUTPUT);
pinMode(COUNTING_LED_PIN, OUTPUT);
}
void setup() {
Serial.begin(SERIAL_BAUD);
while (!Serial) {
delay(300);
}
Serial.println("----------------------------------------------");
Serial.println("| Custom FSM - Soft Power State Machine Test |");
Serial.println("----------------------------------------------");
//void begin(byte attachTo, byte buttonMode = INPUT_PULLUP, boolean activeLow = true);
setup_button();
setup_leds();
}
// LOOP FUNCTION /////////////////////////////////////////////////
void loop() {
button.loop();
}
/////////////////////////////////////////////////////////////////