blob: 8067cb4cd67e22da82d02309675a103180b67bf9 (
plain)
- // 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 <EasyButton.h>
- #include <BlinkControl.h>
- const int longpress_duration = 2000; // time in milliseconds
- // use built-in buttons and LEDs when possible
- #if defined(ESP32)
- // dirty hack: assume that any ESP32 board is a Lilygo T5 V2.2
- #define LILYGO_T5_V22
- #include "boards.h" // source: https://github.com/lewisxhe/GxEPD/blob/master/src/boards.h
- #define HAS_DISPLAY
- const byte BUTTON_PIN_MOVE = BUTTON_1;
- const byte BUTTON_PIN_SELECT = BUTTON_2;
- BlinkControl led(LED_PIN);
- #else
- const byte BUTTON_PIN_MOVE = 2;
- const byte BUTTON_PIN_SELECT = 3;
- BlinkControl led(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);
- #if defined(HAS_DISPLAY)
- #define ENABLE_GxEPD2_GFX 1
- #include <GxEPD2_BW.h>
- #include <Fonts/FreeMonoBold9pt7b.h>
- #include <U8g2_for_Adafruit_GFX.h>
- // source: https://github.com/ZinggJM/GxEPD2/blob/master/examples/GxEPD2_Example/GxEPD2_display_selection.h#L192
- GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> displayEPaper(GxEPD2_290(EPD_CS, EPD_DC, EPD_RSET, EPD_BUSY));
- U8G2_FOR_ADAFRUIT_GFX u8g2;
- #endif
- 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);
- led.begin();
- led.breathe(2000);
- displayEPaper.init(115200, true, 2, false);
- u8g2.begin(displayEPaper);
- }
- void loop() {
- led.loop();
- button_move.read();
- button_select.read();
- }
- #if (ESP32)
- IRAM_ATTR // avoid crash e.g. when other code reads SD card
- #endif
- void onButtonMovePressed() {
- Serial.println("button MOVE clicked");
- led.blink2();
- }
- #if (ESP32)
- IRAM_ATTR // avoid crash e.g. when other code reads SD card
- #endif
- void onButtonMoveLongpressed() {
- Serial.println("button MOVE long-clicked");
- led.off();
- }
- #if (ESP32)
- IRAM_ATTR // avoid crash e.g. when other code reads SD card
- #endif
- void onButtonSelectPressed() {
- Serial.println("button SELECT clicked");
- led.on();
- }
|