#include #define NUM_PIXELS 1 // Number of NeoPixel LEDs #define PIN 12 // Pin connected to the NeoPixel #define POWER 11 // Pin controlling power to the NeoPixel #define BUTTON_PIN D1 // Pin connected to the button Adafruit_NeoPixel pixels(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800); const int ledPins[] = {25, 26, D6, D7}; // Array containing the pins for the non-NeoPixel LEDs const int numLeds = 4; // Ensure this matches the number of elements in ledPins int buttonState; int lastButtonState = LOW; int currentSequence = 0; // Tracks the current sequence to be displayed void setup() { pinMode(POWER, OUTPUT); digitalWrite(POWER, HIGH); // Activates power to the NeoPixel pixels.begin(); // Initializes the NeoPixel LED for(int i = 0; i < numLeds; i++) { pinMode(ledPins[i], OUTPUT); // Sets each LED pin as an output } pinMode(BUTTON_PIN, INPUT); // Sets the button pin as an input } void loop() { buttonState = digitalRead(BUTTON_PIN); // Reads the current state of the button // Detects a button press (rising edge) if (buttonState == HIGH && lastButtonState == LOW) { delay(50); // Debounce to prevent reading the button press multiple times currentSequence = (currentSequence + 1) % 7; // Cycles through 7 sequences // Wait for button release to avoid multiple increments while(digitalRead(BUTTON_PIN) == HIGH) { delay(10); } } lastButtonState = buttonState; // Updates the last button state for the next loop iteration // Executes the current lighting sequence based on the value of currentSequence switch (currentSequence) { case 0: fastSequence(); break; case 1: slowSequence(); break; case 2: sequence1(); break; case 3: sequence2(); break; case 4: simultaneousBlink(); break; case 5: zigzag(); break; case 6: turnOff(); break; } } // Fast Sequence: Quickly turns on and off each LED, including the NeoPixel. void fastSequence() { for(int i = 0; i < numLeds; i++) { digitalWrite(ledPins[i], HIGH); // Turns on the LED delay(100); // Short wait for a quick sequence digitalWrite(ledPins[i], LOW); // Turns off the LED } pixels.setPixelColor(0, pixels.Color(193, 72, 72)); // Sets the NeoPixel to a fast green color pixels.show(); delay(100); // Keeps the color for a short time pixels.clear(); // Turns off the NeoPixel pixels.show(); } // Slow Sequence: Slowly turns on and off each LED, including the NeoPixel. void slowSequence() { for(int i = 0; i < numLeds; i++) { digitalWrite(ledPins[i], HIGH); // Turns on the LED delay(500); // Long wait for a slow sequence digitalWrite(ledPins[i], LOW); // Turns off the LED } pixels.setPixelColor(0, pixels.Color(214, 226, 36)); // Sets the NeoPixel to a slow blue color pixels.show(); delay(500); // Keeps the color for a long time pixels.clear(); // Turns off the NeoPixel pixels.show(); } // Sequence 1: A custom sequence with specific color and timing. void sequence1() { for(int i = 0; i <= numLeds; i++) { if (i < numLeds) { digitalWrite(ledPins[i], HIGH); // Turns on each non-NeoPixel LED } else { pixels.setPixelColor(0, pixels.Color(61, 189, 16)); // Sets NeoPixel LED to green pixels.show(); // Updates NeoPixel to display the color } delay(250); // Waits 250 milliseconds if (i < numLeds) { digitalWrite(ledPins[i], LOW); // Turns off each non-NeoPixel LED } else { pixels.clear(); // Clears the NeoPixel LED (turns off) pixels.show(); // Updates NeoPixel } } } // Sequence 2: Another custom sequence with a different color and timing. void sequence2() { for(int i = numLeds; i >= 0; i--) { if (i < numLeds) { digitalWrite(ledPins[i], HIGH); // Turns on each non-NeoPixel LED in reverse order } else { pixels.setPixelColor(0, pixels.Color(27, 226, 232)); // Sets NeoPixel LED to blue pixels.show(); // Updates NeoPixel to display the color } delay(250); // Waits 250 milliseconds if (i < numLeds) { digitalWrite(ledPins[i], LOW); // Turns off each non-NeoPixel LED } else { pixels.clear(); // Clears the NeoPixel LED (turns off) pixels.show(); // Updates NeoPixel } } } // Simultaneous Blink: All LEDs and the NeoPixel blink together. void simultaneousBlink() { for (int i = 0; i < 5; i++) { for (int pin : ledPins) { digitalWrite(pin, HIGH); } pixels.fill(pixels.Color(27, 86, 232)); // Sets to a yellow color pixels.show(); delay(200); for (int pin : ledPins) { digitalWrite(pin, LOW); } pixels.clear(); pixels.show(); delay(200); } } // Zigzag: Turns on the LEDs in a zigzag pattern. void zigzag() { for (int i = 0; i < numLeds; i+=2) { digitalWrite(ledPins[i], HIGH); if (i+1 < numLeds) digitalWrite(ledPins[i+1], LOW); } delay(250); for (int i = 0; i < numLeds; i+=2) { digitalWrite(ledPins[i], LOW); if (i+1 < numLeds) digitalWrite(ledPins[i+1], HIGH); } delay(250); } // Turn Off: Turns off all LEDs, including the NeoPixel. void turnOff() { // Turns off all normal LEDs for (int i = 0; i < numLeds; i++) { digitalWrite(ledPins[i], LOW); } // Turns off the NeoPixel pixels.clear(); // Sets all NeoPixel LEDs to off (black) pixels.show(); // Updates the NeoPixel to display the change }