#include <Adafruit_NeoPixel.h>
#define PIN 38
#define NUMPIXELS 1
Adafruit_NeoPixel pixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Hàm tạo màu cầu vồng
uint32_t Wheel(byte pos) {
pos = 255 - pos;
if (pos < 85) {
return pixel.Color(255 - pos * 3, 0, pos * 3);
}
if (pos < 170) {
pos -= 85;
return pixel.Color(0, pos * 3, 255 - pos * 3);
}
pos -= 170;
return pixel.Color(pos * 3, 255 - pos * 3, 0);
}
void setup() {
pixel.begin();
pixel.setBrightness(50); // giảm sáng cho dịu mắt
}
void loop() {
for (int i = 0; i < 256; i++) {
pixel.setPixelColor(0, Wheel(i));
pixel.show();
delay(10); // chỉnh tốc độ rainbow (nhỏ = nhanh)
}
}