summaryrefslogtreecommitdiff
path: root/main.ino
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2023-10-10 14:37:03 +0200
committerJonas Smedegaard <dr@jones.dk>2023-10-10 14:37:03 +0200
commit1fb1c3b41dd478168fce17f44719f7fda16df55b (patch)
treefc12f8fe08a4c351dbf2867a26e5c72eea149635 /main.ino
initial draft
Diffstat (limited to 'main.ino')
-rw-r--r--main.ino73
1 files changed, 73 insertions, 0 deletions
diff --git a/main.ino b/main.ino
new file mode 100644
index 0000000..62f755a
--- /dev/null
+++ b/main.ino
@@ -0,0 +1,73 @@
+// Pill dispenser
+
+// Inspired by article "Blink Without Delay"
+// https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay
+
+// Inspired by basic usage documentation of GEM library
+// https://github.com/Spirik/GEM
+
+#include <Button.h>
+
+// assume that any ESP32 board is a Lilygo T5 V2.2
+#if defined(ESP32)
+#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;
+#else
+const byte movePin = 2;
+const byte selectPin = 3;
+const int statusPin = LED_BUILTIN; // pin 13 is built-in LED on many Arduino boards
+#endif
+
+Button button1(movePin); // Connect between pin 2 and GND
+
+int i = 0;
+
+void setup() {
+ button1.begin();
+
+ // put your setup code here, to run once:
+ Serial.begin(115200);
+
+ // Emit actions on pin #3
+ pinMode(13, 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;
+ }
+ }
+ }
+}