// Pill dispenser // Inspired by article "Blink Without Delay" // https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay // Inspired by basic usage documentation of GEM library // https://github.com/Spirik/GEM #include const int longpress_duration = 2000; // time in milliseconds #if defined(ESP32) // dirty hack: assume that any ESP32 board is a Lilygo T5 V2.2 #define LILYGO_T5_V22 #endif // use built-in buttons and LEDs when possible #if defined(LILYGO_T5_V22) #include "boards.h" // source: https://github.com/lewisxhe/GxEPD/blob/master/src/boards.h const byte BUTTON_PIN_MOVE = BUTTON_1; const byte BUTTON_PIN_SELECT = BUTTON_2; const int LED_PIN_STATUS = LED_PIN; #else const byte BUTTON_PIN_MOVE = 2; const byte BUTTON_PIN_SELECT = 3; const int LED_PIN_STATUS = LED_BUILTIN; // pin 13 is built-in LED on many Arduino boards #endif // serial port speed #define BAUDRATE 115200 EasyButton button_move(BUTTON_PIN_MOVE); EasyButton button_select(BUTTON_PIN_SELECT); void setup() { Serial.begin(BAUDRATE); while (!Serial) { ; } Serial.println(); button_move.begin(); button_select.begin(); button_move.onPressed(onButtonMovePressed); button_move.onPressedFor(longpress_duration, onButtonMoveLongpressed); button_select.onPressed(onButtonSelectPressed); // Emit actions on pin #3 pinMode(LED_PIN_STATUS, OUTPUT); } void loop() { button_move.read(); button_select.read(); } void onButtonMovePressed() { Serial.println("button MOVE clicked"); } void onButtonMoveLongpressed() { Serial.println("button MOVE long-clicked"); } void onButtonSelectPressed() { Serial.println("button SELECT clicked"); } /* void blink() { state = !state; Serial.println(state); } */