aboutsummaryrefslogtreecommitdiff
path: root/mussel5
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-02-26 13:39:31 +0100
committerJonas Smedegaard <dr@jones.dk>2025-02-26 13:40:18 +0100
commitdbbde95ae72907b6f3ad4731ddcfdb8782b4035b (patch)
tree589c33a7bf1fa0afdeaa424134a8992be70416ac /mussel5
parent981a96f7680cf285ec8d196ad527766b467ad9ac (diff)
add more mussels
Diffstat (limited to 'mussel5')
-rw-r--r--mussel5/mussel5.ino64
1 files changed, 64 insertions, 0 deletions
diff --git a/mussel5/mussel5.ino b/mussel5/mussel5.ino
new file mode 100644
index 0000000..f44c907
--- /dev/null
+++ b/mussel5/mussel5.ino
@@ -0,0 +1,64 @@
+const int buttonPin = 9;
+const int redLED = 3;
+const int greenLED = 4;
+const int yellowLED = 5;
+
+int buttonState = HIGH;
+int lastButtonState = HIGH;
+int clickCount = 0;
+unsigned long lastDebounceTime = 0;
+const unsigned long debounceDelay = 50;
+
+void setup() {
+ pinMode(buttonPin, INPUT_PULLUP);
+ pinMode(redLED, OUTPUT);
+ pinMode(greenLED, OUTPUT);
+ pinMode(yellowLED, OUTPUT);
+ Serial.begin(9600);
+}
+
+void loop() {
+ int reading = digitalRead(buttonPin);
+
+ // Debounce logic
+ if (reading != lastButtonState) {
+ lastDebounceTime = millis();
+ }
+
+ if ((millis() - lastDebounceTime) > debounceDelay) {
+ if (reading == LOW && lastButtonState == HIGH) {
+ clickCount++;
+ if (clickCount > 3) {
+ clickCount = 0; // Reset cycle after 3 clicks
+ }
+ updateLEDs();
+ }
+ }
+
+ lastButtonState = reading;
+}
+
+void updateLEDs() {
+ // Turn off all LEDs first
+ digitalWrite(redLED, LOW);
+ digitalWrite(greenLED, LOW);
+ digitalWrite(yellowLED, LOW);
+
+ switch (clickCount) {
+ case 1:
+ digitalWrite(redLED, HIGH);
+ Serial.println("State: Angry (Red LED ON)");
+ break;
+ case 2:
+ digitalWrite(greenLED, HIGH);
+ Serial.println("State: Happy (Green LED ON)");
+ break;
+ case 3:
+ digitalWrite(yellowLED, HIGH);
+ Serial.println("State: Unsure (Yellow LED ON)");
+ break;
+ case 0:
+ Serial.println("State: Off (All LEDs OFF)");
+ break;
+ }
+}