#include <Adafruit_NeoPixel.h>
#define NUMPIXELS 16 // Number of pixels in each ring
#define PIN1 2 // Digital pin connected to the first NeoPixel ring
#define PIN2 3 // Digital pin connected to the second NeoPixel ring
#define BUTTON_PIN 4 // Digital pin connected to the button
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
bool ledsOn = false;
void setup() {
strip1.begin();
strip2.begin();
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // button pressed
if (!ledsOn) {
fadeOn();
ledsOn = true;
} else {
fadeOff();
ledsOn = false;
}
delay(500); // Debounce delay to prevent multiple rapid button presses
}
}
void fadeOn() {
for (int i = 0; i < NUMPIXELS; i++) {
strip1.setPixelColor(i, strip1.Color(255, 0, 0)); // Red color, you can change this
strip1.show();
delay(150); // Adjust the delay for the speed of fading
}
delay(500); // Adjust the delay before turning on the second ring
for (int i = 0; i < NUMPIXELS; i++) {
strip2.setPixelColor(i, strip2.Color(0, 0, 255)); // Blue color, you can change this
strip2.show();
delay(150);
}
}
void fadeOff() {
for (int i = 0; i < NUMPIXELS; i++) {
strip2.setPixelColor(i, strip2.Color(0, 0, 0)); // Turn off pixels
strip2.show();
delay(150);
}
delay(500);
for (int i = 0; i < NUMPIXELS; i++) {
strip1.setPixelColor(i, strip1.Color(0, 0, 0)); // Turn off pixels
strip1.show();
delay(150);
}
}