#include <Adafruit_NeoPixel.h>

#define DIN_PIN   22    // ESP32 connected to WS2812B_Din
#define LED_CNT 8   // 8個燈
//變數名稱為leds的Adafruit_NeoPixel 類別
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_CNT, DIN_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode (DIN_PIN, OUTPUT);    //串列輸出腳
  leds.begin();             //初始化
}

void loop() {
  leds.clear();             //清除 
  for (int i = 0; i < 8; i++) {         
    leds.setPixelColor(i, leds.Color(255, 0, 0));  //紅
    leds.show();                                         
    delay(100); 
  }
  for (int i = 0; i < 8; i++) {         
    leds.setPixelColor(i, leds.Color(255, 255, 0)); //黃
    leds.show();                                         
    delay(100); 
  }
  for (int i = 0; i < 8; i++) {         
    leds.setPixelColor(i, leds.Color(0, 255, 0));   //綠
    leds.show();                                         
    delay(100);   
  }
  for (int i = 0; i < 8; i++) {         
    leds.setPixelColor(i, leds.Color(0, 255, 255)); //青
    leds.show();                                         
    delay(100);  
  }
  for (int i = 0; i < 8; i++) {        
    leds.setPixelColor(i, leds.Color(0, 0, 255)); //藍
    leds.show();                                         
    delay(100); 
  }
  for (int i = 0; i < 8; i++) {         
    leds.setPixelColor(i, leds.Color(255, 0, 255)); //紫
    leds.show();                                         
    delay(100); 
  }
   for (int i = 0; i < 8; i++) {         
    leds.setPixelColor(i, leds.Color(255, 255, 255)); //紫
    leds.show();                                         
    delay(100); 
  }
}