How to use NeoPixel

  1. How to connect
  2. Arduino Library installation: Adafruit_NeoPixel https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation
  3. Verify with example code: Adafruit NeoPixel→simple
  4. Function explain

NeoPixel blink

#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:

  1. NeoPixel Function explain

    strip.setPixelColor(n, red, green, blue);
    strip.setPixelColor(n, color);
    strip.Color(red, green, blue);
    strip.show();
    
  2. For loop for()

NeoPixel blink without delay()