diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-01 22:18:26 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-01 22:18:26 +0200 |
commit | 223894c7305a084130edfba75108c87b2c453691 (patch) | |
tree | 24c6110430cabc81c27584425e5fcca51c4e387b /mussel5/mussel5.ino | |
parent | aaf35ec4d317224b6fa9a226479f0d56fc266eb0 (diff) |
add library as appendix; add diagrams to library; drop individual mussel sketches
Diffstat (limited to 'mussel5/mussel5.ino')
-rw-r--r-- | mussel5/mussel5.ino | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/mussel5/mussel5.ino b/mussel5/mussel5.ino deleted file mode 100644 index 12f42d6..0000000 --- a/mussel5/mussel5.ino +++ /dev/null @@ -1,74 +0,0 @@ -/// mussel_mood.ino - Button-controlled LED system with state tracking -/// -/// SPDX-License-Identifier: GPL-3.0-or-later -/// SPDX-FileCopyrightText: 2025 Tanishka Suwalka <tanishkas@ruc.dk> -/// -/// This code toggles LEDs based on button presses, cycling through Red, Green, and Yellow states. - -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); // Enable internal pull-up resistor for button - pinMode(redLED, OUTPUT); - pinMode(greenLED, OUTPUT); - pinMode(yellowLED, OUTPUT); - Serial.begin(9600); // Initialize serial monitor for debugging -} - -void loop() { - int reading = digitalRead(buttonPin); // Read button state - - // Debounce logic: Ensures a single press isn't detected multiple times - if (reading != lastButtonState) { - lastDebounceTime = millis(); // Reset debounce timer - } - - if ((millis() - lastDebounceTime) > debounceDelay) { - // Check for button press (transition from HIGH to LOW) - if (reading == LOW && lastButtonState == HIGH) { - clickCount++; // Increment click count - if (clickCount > 3) { - clickCount = 0; // Reset cycle after 3 clicks - } - updateLEDs(); - } - } - - lastButtonState = reading; // Update button state -} - -/// updateLEDs() - Updates LED states based on click count -void updateLEDs() { - // Turn off all LEDs first - digitalWrite(redLED, LOW); - digitalWrite(greenLED, LOW); - digitalWrite(yellowLED, LOW); - - // Determine which LED to turn on - 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; - } -} |