// --------------------------------------------------------------------------------
/*
12 NeoPixel LED Ring 設定顏色及滾動
[學習重點]
1. 認識 NeoPixel LED Ring
2. 認識 Library
3. 建立物件 Object
4. 認識子程式
[挑戰]
- 加多一個 NeoPixel LED Ring
Created by Jason on 12 Aug 2022.
*/
// --------------------------------------------------------------------------------
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel ring = Adafruit_NeoPixel(16, 9); // 建立物件 (16 = LED 數量, 9 = Pin)
void setup() {
ring.begin();
ring.setBrightness(255); // 設定亮度 0 - 255
ring.show(); // 將設定顯示出來
}
void loop() {
colorWipe(255, 0, 0, 50); // 依序亮紅色
colorWipe(255, 128, 0, 50); // 依序亮橙色
colorWipe(255, 255, 0, 50); // 依序亮黃色
colorWipe(0, 255, 0, 50); // 依序亮綠色
colorWipe(0, 255, 255, 50); // 依序亮青色
colorWipe(0, 0, 255, 50); // 依序亮藍色
colorWipe(255, 0, 255, 50); // 依序紫色
}
// 著色特效:依序顯示指定的 rgb 顏色, 每顯示一顆就暫停 wait 毫秒
void colorWipe(byte r, byte g, byte b, int wait) {
for (unsigned i = 0; i < ring.numPixels(); i++) { // 由0開始依序點亮
ring.setPixelColor(i, r, g, b); // 點亮指定的顏色
ring.show(); // 將設定顯示出來
delay(wait); // 延時
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT