#include <Adafruit_NeoPixel.h>
#define LED_PIN 5 // Chân điều khiển WS2812 -> đổi tùy bro đấu
#define LED_COUNT 8 // Số lượng LED trong strip
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Tắt hết LED ban đầu
strip.setBrightness(100); // Độ sáng (0-255)
}
void loop() {
colorWipe(strip.Color(255, 0, 0), 50); // Đỏ
colorWipe(strip.Color(0, 255, 0), 50); // Lục
colorWipe(strip.Color(0, 0, 255), 50); // Xanh
rainbow(10); // Hiệu ứng cầu vồng
}
// ====== HIỆU ỨNG ======
void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
void rainbow(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
strip.rainbow(firstPixelHue);
strip.show();
delay(wait);
}
}