How to use NeoPixel
#include <Adafruit_NeoPixel.h>
#define LED_PIN 5 // NeoPixel 資料腳位
#define NUM_LEDS 12 // LED 數量
// 建立 NeoPixel 物件
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // 開始時關閉所有 LED
}
void loop() {
// 逐一設定每顆 LED 為紅色 (255, 0, 0)
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
}
strip.show();
delay(1000); // 每秒更新一次
}
Teaching points:
NeoPixel Function explain
strip.setPixelColor(n, red, green, blue);
strip.setPixelColor(n, color);
strip.Color(red, green, blue);
strip.show();
For loop for()
delay()