summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2023-10-11 10:04:48 +0200
committerJonas Smedegaard <dr@jones.dk>2023-10-11 10:04:48 +0200
commit01499c553711feab8c1271f774a93c4a23d27eed (patch)
treed0fdac39ee5db0fc3ba61f84ef07a3899a4ebcb7
parent1fb1c3b41dd478168fce17f44719f7fda16df55b (diff)
use EasyButton (not Button)
-rw-r--r--main.ino88
1 files changed, 43 insertions, 45 deletions
diff --git a/main.ino b/main.ino
index 62f755a..ee926bf 100644
--- a/main.ino
+++ b/main.ino
@@ -6,68 +6,66 @@
// Inspired by basic usage documentation of GEM library
// https://github.com/Spirik/GEM
-#include <Button.h>
+#include <EasyButton.h>
+
+const int longpress_duration = 2000; // time in milliseconds
-// assume that any ESP32 board is a Lilygo T5 V2.2
#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"
-const byte movePin = BUTTON_1;
-const byte selectPin = BUTTON_1;
-const int statusPin = LED_PIN;
+#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 movePin = 2;
-const byte selectPin = 3;
-const int statusPin = LED_BUILTIN; // pin 13 is built-in LED on many Arduino boards
+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
-Button button1(movePin); // Connect between pin 2 and GND
+// serial port speed
+#define BAUDRATE 115200
-int i = 0;
+EasyButton button_move(BUTTON_PIN_MOVE);
+EasyButton button_select(BUTTON_PIN_SELECT);
void setup() {
- button1.begin();
+ Serial.begin(BAUDRATE);
- // put your setup code here, to run once:
- Serial.begin(115200);
+ 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(13, OUTPUT);
+ pinMode(LED_PIN_STATUS, OUTPUT);
}
void loop() {
- // put your main code here, to run repeatedly:
-
- // læs om der bliver trykket på knappen
- // hvis der trykes - så udfør noget. (her vis tekst på skærm)
- if (button1.pressed()) {
- Serial.println("action requested!");
- }
-
- //Hvis ovenstående sker, så giv output i pin #3 (evt lys) - her blinker den.
- if (i < 8) {
- digitalWrite(13, LOW);
- i++;
- } else {
- digitalWrite(13, HIGH);
- i = 0;
- }
- delay(100);
-
- //Næste trin skal vi have den til at aflæse knappen igen.
- if (button1.pressed()) {
- Serial.println("hvilken borger?");
- digitalWrite(13, HIGH);
- while (true) {
- delay(100);
- if (button1.pressed()) {
- Serial.println("stoooop!");
- break;
- }
- }
- }
+ button_move.read();
+ button_select.read();
+}
+
+void onButtonMovePressed() {
+ Serial.print("button MOVE clicked");
+}
+
+void onButtonMoveLongpressed() {
+ Serial.print("button MOVE long-clicked");
+}
+
+void onButtonSelectPressed() {
+ Serial.print("button SELECT clicked");
+}
+
+/*
+void blink() {
+ state = !state;
+ Serial.println(state);
}
+*/