#include <Adafruit_NeoPixel.h>
#define PIN 6 // DI 핀번호
#define N_LEDS 8 // 네오픽셀 LED 갯수
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
//NEO_GRB <= 네오픽셀 타입 , NEO_KHZ800 <= 클럭 주파수
void setup() {
strip.setBrightness(100); // 네오픽셀 밝기
strip.begin(); // 네오픽셀 시작
}
void loop() {
int R = 0;
int G = 0;
int B = 0;
R = 255;
G = 0;
for (int B = 0; B < 256 ; B+=50) {
chase(strip.Color(R, G, 0));
R -= 50;
G += 50;
}
G = 255;
B = 0;
for (int R = 0; R < 256 ; R+=50) {
chase(strip.Color(0, G, B));
G -= 50;
B += 50;
}
B = 255;
R = 0;
for (int G = 0; G < 256 ; G+=50) {
chase(strip.Color(R, 0, B));
B -= 50;
R += 50;
}
}
static void chase(uint32_t c) {
for (uint16_t i = 0; i < strip.numPixels() + 4; i++) {
strip.setPixelColor(i , c); // i 번째 픽셀에 LED 색상 지정
strip.setPixelColor(i-3, 0); // i-3 픽셀에 색상 0을 지정하여 지움
strip.show();
delay(80);
}
/* 랜덤 위치 그리기
uint16_t i=random(0,8);
uint16_t j=random(0,8);
strip.setPixelColor(i , c); // i 번째 픽셀에 LED 색상 지정
strip.setPixelColor(j , c); // j 번째 픽셀에 LED 색상 지정
strip.show();
strip.setPixelColor(i , 0); // i 번째 픽셀지움
strip.setPixelColor(j , 0); // j 번째 픽셀지움
delay(100);
*/
}