#include <Adafruit_NeoPixel.h>
// Define Neopixel Ring properties
#define LED_PIN 6 // Pin connected to the Neopixel ring
#define NUM_LEDS 16 // Number of LEDs in the ring
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
// Button setup
#define BUTTON_PIN 2 // Pin connected to the button
int mode = 0; // 0: Off, 1: Light-Blue, 2: Flashing
unsigned long flashInterval = 100; // Set flash interval in milliseconds
unsigned long lastFlashTime = 0; // Timer for flashing effect
bool flashState = false; // Flash toggle
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // Button pin with internal pull-up
strip.begin();
strip.show(); // Initialize all LEDs off
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // Check if user has pressed the button
mode = (mode + 1) % 3; // Cycle between 0, 1, and 2
delay(500); // wait for 500 milliseconds
}
switch (mode) { // Execute mode according to mode
case 0:
turnOffLEDs();
break;
case 1:
solidColor(0, 128, 255); // Light-blue (R=0, G=128, B=255)
break;
case 2:
flashingEffect();
break;
}
}
// Turn off all LEDs
void turnOffLEDs() {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 0, 0); // Black/off
}
strip.show();
}
// Set solid color
void solidColor(int red, int green, int blue) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, red, green, blue);
}
strip.show();
}
// Flashing effect
void flashingEffect() {
unsigned long currentTime = millis();
if (currentTime - lastFlashTime > flashInterval) { // Change flash interval here
lastFlashTime = currentTime;
flashState = !flashState;
if (flashState) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 128, 255); // Light-blue
}
} else {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 255, 0); // Yellow
}
}
strip.show();
}
}