summaryrefslogtreecommitdiff
path: root/main.ino
blob: a4c64bc2198351b4057b2944eda3723bf5d0d310 (plain)
  1. // Pill dispenser
  2. // Inspired by article "Blink Without Delay"
  3. // https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay
  4. // Inspired by basic usage documentation of GEM library
  5. // https://github.com/Spirik/GEM
  6. #include <EasyButton.h>
  7. #include <BlinkControl.h>
  8. const int longpress_duration = 2000; // time in milliseconds
  9. // use built-in buttons and LEDs when possible
  10. #if defined(ESP32)
  11. // dirty hack: assume that any ESP32 board is a Lilygo T5 V2.2
  12. #define LILYGO_T5_V22
  13. #include "boards.h" // source: https://github.com/lewisxhe/GxEPD/blob/master/src/boards.h
  14. const byte BUTTON_PIN_MOVE = BUTTON_1;
  15. const byte BUTTON_PIN_SELECT = BUTTON_2;
  16. BlinkControl led(LED_PIN);
  17. #else
  18. const byte BUTTON_PIN_MOVE = 2;
  19. const byte BUTTON_PIN_SELECT = 3;
  20. BlinkControl led(LED_BUILTIN); // pin 13 is built-in LED on many Arduino boards
  21. #endif
  22. // serial port speed
  23. #define BAUDRATE 115200
  24. EasyButton button_move(BUTTON_PIN_MOVE);
  25. EasyButton button_select(BUTTON_PIN_SELECT);
  26. void setup() {
  27. Serial.begin(BAUDRATE);
  28. while (!Serial) {
  29. ;
  30. }
  31. Serial.println();
  32. button_move.begin();
  33. button_select.begin();
  34. button_move.onPressed(onButtonMovePressed);
  35. button_move.onPressedFor(longpress_duration, onButtonMoveLongpressed);
  36. button_select.onPressed(onButtonSelectPressed);
  37. led.begin();
  38. led.breathe(2000);
  39. }
  40. void loop() {
  41. led.loop();
  42. button_move.read();
  43. button_select.read();
  44. }
  45. #if (ESP32)
  46. IRAM_ATTR // avoid crash e.g. when other code reads SD card
  47. #endif
  48. void onButtonMovePressed() {
  49. Serial.println("button MOVE clicked");
  50. led.blink2();
  51. }
  52. #if (ESP32)
  53. IRAM_ATTR // avoid crash e.g. when other code reads SD card
  54. #endif
  55. void onButtonMoveLongpressed() {
  56. Serial.println("button MOVE long-clicked");
  57. led.off();
  58. }
  59. #if (ESP32)
  60. IRAM_ATTR // avoid crash e.g. when other code reads SD card
  61. #endif
  62. void onButtonSelectPressed() {
  63. Serial.println("button SELECT clicked");
  64. led.on();
  65. }