summaryrefslogtreecommitdiff
path: root/main.ino
blob: 88d132fe503b123d4fc2e02c934221c2ae9e2012 (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. void onButtonMovePressed() {
  46. Serial.println("button MOVE clicked");
  47. led.blink2();
  48. }
  49. void onButtonMoveLongpressed() {
  50. Serial.println("button MOVE long-clicked");
  51. led.off();
  52. }
  53. void onButtonSelectPressed() {
  54. Serial.println("button SELECT clicked");
  55. led.on();
  56. }