summaryrefslogtreecommitdiff
path: root/main.ino
blob: 571bfe075999a8b7a32f62a5e0e609e98bb2f2bc (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. const int longpress_duration = 2000; // time in milliseconds
  8. #if defined(ESP32)
  9. // dirty hack: assume that any ESP32 board is a Lilygo T5 V2.2
  10. #define LILYGO_T5_V22
  11. #endif
  12. // use built-in buttons and LEDs when possible
  13. #if defined(LILYGO_T5_V22)
  14. #include "boards.h" // source: https://github.com/lewisxhe/GxEPD/blob/master/src/boards.h
  15. const byte BUTTON_PIN_MOVE = BUTTON_1;
  16. const byte BUTTON_PIN_SELECT = BUTTON_2;
  17. const int LED_PIN_STATUS = LED_PIN;
  18. #else
  19. const byte BUTTON_PIN_MOVE = 2;
  20. const byte BUTTON_PIN_SELECT = 3;
  21. const int LED_PIN_STATUS = LED_BUILTIN; // pin 13 is built-in LED on many Arduino boards
  22. #endif
  23. // serial port speed
  24. #define BAUDRATE 115200
  25. EasyButton button_move(BUTTON_PIN_MOVE);
  26. EasyButton button_select(BUTTON_PIN_SELECT);
  27. void setup() {
  28. Serial.begin(BAUDRATE);
  29. while (!Serial) {
  30. ;
  31. }
  32. Serial.println();
  33. button_move.begin();
  34. button_select.begin();
  35. button_move.onPressed(onButtonMovePressed);
  36. button_move.onPressedFor(longpress_duration, onButtonMoveLongpressed);
  37. button_select.onPressed(onButtonSelectPressed);
  38. // Emit actions on pin #3
  39. pinMode(LED_PIN_STATUS, OUTPUT);
  40. }
  41. void loop() {
  42. button_move.read();
  43. button_select.read();
  44. }
  45. void onButtonMovePressed() {
  46. Serial.println("button MOVE clicked");
  47. }
  48. void onButtonMoveLongpressed() {
  49. Serial.println("button MOVE long-clicked");
  50. }
  51. void onButtonSelectPressed() {
  52. Serial.println("button SELECT clicked");
  53. }
  54. /*
  55. void blink() {
  56. state = !state;
  57. Serial.println(state);
  58. }
  59. */