diff options
Diffstat (limited to 'main.ino')
-rw-r--r-- | main.ino | 88 |
1 files changed, 43 insertions, 45 deletions
@@ -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); } +*/ |