// WS2812 / NeoPixel 48-LED Test Sketch
// Author: ChatGPT (for Muna)
// Use: Connect DATA to pin 6, VCC to 5V, GND to GND
// Library: Adafruit_NeoPixel
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6 // Data pin (change if aap alag pin use kar rahe ho)
#define LED_COUNT 48 // Total LEDs
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
delay(500);
}
void loop() {
// 1) All LEDs red (quick check)
colorFill(strip.Color(150, 0, 0), 500);
// 2) Color wipe (green -> blue -> off)
colorWipe(strip.Color(0, 150, 0), 30);
colorWipe(strip.Color(0, 0, 150), 30);
colorWipe(strip.Color(0, 0, 0), 10);
// 3) Rainbow sweep
rainbow(5);
// 4) Theater chase (white)
theaterChase(strip.Color(120, 120, 120), 50);
// 5) Blink all colors (red, green, blue)
blinkAll(strip.Color(200, 0, 0), 300, 3);
blinkAll(strip.Color(0, 200, 0), 300, 3);
blinkAll(strip.Color(0, 0, 200), 300, 3);
// 6) Rainbow cycle (slower)
rainbowCycle(3);
}
// ---------- Helper patterns ----------
void colorFill(uint32_t color, uint16_t wait_ms) {
for (uint16_t i = 0; i < LED_COUNT; i++) {
strip.setPixelColor(i, color);
}
strip.show();
delay(wait_ms);
}
void colorWipe(uint32_t color, uint8_t wait_ms) {
for (uint16_t i = 0; i < LED_COUNT; i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait_ms);
}
}
void blinkAll(uint32_t color, uint16_t ms, uint8_t times) {
for (uint8_t t = 0; t < times; t++) {
colorFill(color, ms);
colorFill(strip.Color(0,0,0), ms);
}
}
void theaterChase(uint32_t color, uint8_t wait_ms) {
for (int j = 0; j < 10; j++) { // number of cycles
for (int q = 0; q < 3; q++) {
for (uint16_t i = 0; i < LED_COUNT; i += 3) {
strip.setPixelColor(i + q, color); // turn every third pixel on
}
strip.show();
delay(wait_ms);
for (uint16_t i = 0; i < LED_COUNT; i += 3) {
strip.setPixelColor(i + q, 0); // turn every third pixel off
}
}
}
}
void rainbow(uint8_t wait_ms) {
for (long firstPixelHue = 0; firstPixelHue < 5*65536L; firstPixelHue += 256) {
for (int i = 0; i < LED_COUNT; i++) {
int pixelHue = firstPixelHue + (i * 65536L / LED_COUNT);
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show();
delay(wait_ms);
}
}
void rainbowCycle(uint8_t wait_ms) {
for (uint16_t j = 0; j < 256; j++) { // one cycle of all colors on the wheel
for (uint16_t i = 0; i < LED_COUNT; i++) {
uint32_t c = Wheel(((i * 256 / LED_COUNT) + j) & 255);
strip.setPixelColor(i, c);
}
strip.show();
delay(wait_ms);
}
}
// Input 0-255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}