#include <Adafruit_NeoPixel.h> // Include the NeoPixel library
#define PIN 6 // Data pin connected to the LED strip
#define NUM_LEDS 8 // Number of LEDs on the strip
// Create the strip instance: 6 LEDs, on pin 6, GRB pixel order, 800 kHz timing
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin(); // Initialize the strip object
strip.setBrightness(255); // Global brightness (0..255)
// Set all LEDs to red and send the data to the strip
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
}
strip.show();
}
void loop() {
// Intentionally empty: static color example
}
#include <Adafruit_NeoPixel.h> // NeoPixel control library
#define PIN 6 // LED strip data pin
#define NUM_LEDS 8 // Number of LEDs
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Non-blocking blink timing state (avoids delay())
unsigned long lastToggle = 0; // Timestamp of the last toggle
const unsigned long intervalMs = 500; // Blink period in milliseconds
bool isOn = false; // Current on/off state
// Helper: set all pixels to the same color
void setAll(uint32_t c) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, c);
}
}
void setup() {
strip.begin();
strip.setBrightness(255);
strip.show(); // Initialize LEDs to off
}
void loop() {
unsigned long now = millis();
if (now - lastToggle >= intervalMs) { // Time to toggle?
lastToggle = now;
isOn = !isOn;
setAll(isOn ? strip.Color(255, 0, 0) : strip.Color(0, 0, 0));
strip.show();
}
}
#include <Adafruit_NeoPixel.h> // NeoPixel control library
#define PIN 6 // LED strip data pin
#define NUM_LEDS 8 // Number of LEDs
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Knight Rider animation state
int position = 0; // Current LED index
int direction = 1; // 1 = forward, -1 = backward
unsigned long lastStep = 0; // Last animation step time
const unsigned long speedMs = 60; // Step interval (smaller = faster)
// Helper: clear all pixels quickly
void clearAll() {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0);
}
}
void setup() {
strip.begin();
strip.setBrightness(255);
strip.show();
}
void loop() {
unsigned long now = millis();
if (now - lastStep >= speedMs) { // Time for the next frame
lastStep = now;
clearAll();
// Main red dot at current position
strip.setPixelColor(position, strip.Color(255, 0, 0));
// Simple red trail on both sides (dimmed)
if (position - 1 >= 0) strip.setPixelColor(position - 1, strip.Color(80, 0, 0));
if (position + 1 < NUM_LEDS) strip.setPixelColor(position + 1, strip.Color(80, 0, 0));
strip.show();
// Move the dot and bounce at the ends
position += direction;
if (position == 0 || position == NUM_LEDS - 1) {
direction = -direction;
}
}
}
#include <Adafruit_NeoPixel.h> // NeoPixel control library
#define PIN 6 // LED strip data pin
#define NUM_LEDS 8 // Number of LEDs
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Periodically pick a new random color for all LEDs (non-blocking)
unsigned long lastChange = 0; // Time of last color change
const unsigned long changeEveryMs = 200; // Change frequency in ms
// Helper: set all pixels
void setAll(uint32_t c) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, c);
}
}
void setup() {
strip.begin();
strip.setBrightness(255);
randomSeed(analogRead(A0)); // Seed RNG for different sequences
}
void loop() {
unsigned long now = millis();
if (now - lastChange >= changeEveryMs) { // Time for a new color?
lastChange = now;
uint8_t r = random(256);
uint8_t g = random(256);
uint8_t b = random(256);
setAll(strip.Color(r, g, b));
strip.show();
}
}
#include <Adafruit_NeoPixel.h> // NeoPixel control library
#define PIN 6 // LED strip data pin
#define NUM_LEDS 8 // Number of LEDs
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Smoothly fade brightness up and down (non-blocking)
unsigned long lastStep = 0; // Last update timestamp
const unsigned long stepMs = 20; // Time between brightness updates
int level = 0; // Current brightness level (0..255)
int dir = 1; // +1 increasing, -1 decreasing
void setAll(uint32_t c) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, c);
}
}
void setup() {
strip.begin();
strip.setBrightness(255);
}
void loop() {
unsigned long now = millis();
if (now - lastStep >= stepMs) { // Update on schedule
lastStep = now;
level += dir; // Step brightness
if (level >= 255 || level <= 0) {
dir = -dir; // Reverse at the ends
level = constrain(level, 0, 255);
}
setAll(strip.Color(level, level, level));
strip.show();
}
}
#include <Adafruit_NeoPixel.h> // NeoPixel control library
#define PIN 6 // LED strip data pin
#define NUM_LEDS 8 // Number of LEDs
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
unsigned long lastStep = 0;
const unsigned long stepMs = 20; // Smooth updates
int level = 0; // 0..255
int dir = 1; // Fade up/down
void setAll(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < NUM_LEDS; i++) strip.setPixelColor(i, strip.Color(r, g, b));
}
void setup() {
strip.begin();
strip.setBrightness(255);
}
void loop() {
unsigned long now = millis();
if (now - lastStep >= stepMs) {
lastStep = now;
level += dir;
if (level >= 255 || level <= 0) { dir = -dir; level = constrain(level, 0, 255); }
// Warm white: more red, some green, little blue
setAll(level, level * 0.45, level * 0.05);
}
strip.show();
}
#include <Adafruit_NeoPixel.h> // NeoPixel control library
#define PIN 6 // LED strip data pin
#define NUM_LEDS 8 // Number of LEDs
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Cycle a rainbow across the LEDs (non-blocking)
unsigned long lastStep = 0; // Last hue shift timestamp
const unsigned long stepMs = 60; // Time between hue shifts
uint16_t offset = 0; // Moving offset through the color wheel
// Map a 0..255 position onto an RGB rainbow color
uint32_t wheel(byte pos) {
pos = 255 - pos;
if (pos < 85) {
return strip.Color(255 - pos * 3, 0, pos * 3);
}
if (pos < 170) {
pos -= 85;
return strip.Color(0, pos * 3, 255 - pos * 3);
}
pos -= 170;
return strip.Color(pos * 3, 255 - pos * 3, 0);
}
void setup() {
strip.begin();
strip.setBrightness(255);
}
void loop() {
unsigned long now = millis();
if (now - lastStep >= stepMs) { // Time to advance the rainbow
lastStep = now;
for (int i = 0; i < NUM_LEDS; i++) {
// Evenly space hues across the strip, then add a moving offset
uint8_t hue = (i * (256 / NUM_LEDS) + offset) & 255;
strip.setPixelColor(i, wheel(hue));
}
strip.show();
offset++; // Slowly rotate the color wheel
}
}