aboutsummaryrefslogtreecommitdiff
path: root/mussel5/mussel5.ino
blob: f44c907a870b16bdcc904687f9bd314414c6710f (plain)
  1. const int buttonPin = 9;
  2. const int redLED = 3;
  3. const int greenLED = 4;
  4. const int yellowLED = 5;
  5. int buttonState = HIGH;
  6. int lastButtonState = HIGH;
  7. int clickCount = 0;
  8. unsigned long lastDebounceTime = 0;
  9. const unsigned long debounceDelay = 50;
  10. void setup() {
  11. pinMode(buttonPin, INPUT_PULLUP);
  12. pinMode(redLED, OUTPUT);
  13. pinMode(greenLED, OUTPUT);
  14. pinMode(yellowLED, OUTPUT);
  15. Serial.begin(9600);
  16. }
  17. void loop() {
  18. int reading = digitalRead(buttonPin);
  19. // Debounce logic
  20. if (reading != lastButtonState) {
  21. lastDebounceTime = millis();
  22. }
  23. if ((millis() - lastDebounceTime) > debounceDelay) {
  24. if (reading == LOW && lastButtonState == HIGH) {
  25. clickCount++;
  26. if (clickCount > 3) {
  27. clickCount = 0; // Reset cycle after 3 clicks
  28. }
  29. updateLEDs();
  30. }
  31. }
  32. lastButtonState = reading;
  33. }
  34. void updateLEDs() {
  35. // Turn off all LEDs first
  36. digitalWrite(redLED, LOW);
  37. digitalWrite(greenLED, LOW);
  38. digitalWrite(yellowLED, LOW);
  39. switch (clickCount) {
  40. case 1:
  41. digitalWrite(redLED, HIGH);
  42. Serial.println("State: Angry (Red LED ON)");
  43. break;
  44. case 2:
  45. digitalWrite(greenLED, HIGH);
  46. Serial.println("State: Happy (Green LED ON)");
  47. break;
  48. case 3:
  49. digitalWrite(yellowLED, HIGH);
  50. Serial.println("State: Unsure (Yellow LED ON)");
  51. break;
  52. case 0:
  53. Serial.println("State: Off (All LEDs OFF)");
  54. break;
  55. }
  56. }