LED環形流水燈
文章參考自:ESP32 AND WS2812 RGB LED RING EXAMPLE
接線:
接腳定義:
環形LED是WS2812晶片,上面就三支接腳:
DI:Data Input
5v: 接單晶片主板上的Vout (3.3V或5v)
GND: 接地 ground
DO: Data Output (WS2812燈條串接下一個組燈條用)
程式碼:
#include <Adafruit_NeoPixel.h> #define PIN 15 // How many NeoPixels are attached to the Arduino? #define NUMPIXELS 45 //45顆LED Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int delayval = 50; // delay for half a second void setup() { pixels.begin(); // This initializes the NeoPixel library. } void loop() { for(int i=0;i<NUMPIXELS;i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, pixels.Color(255,0,0)); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. delay(delayval); // Delay for a period of time (in milliseconds). } for(int i=0;i<NUMPIXELS;i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, pixels.Color(0,255,0)); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. delay(delayval); // Delay for a period of time (in milliseconds). } for(int i=0;i<NUMPIXELS;i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, pixels.Color(0,0,255)); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. delay(delayval); // Delay for a period of time (in milliseconds). } }
研究這個主題,請下關鍵字:
- LED Ring/LED環形燈
- WS2812
- NeoPixel程式庫
用 Google搜尋後,再用圖片的方式來找出需要的資訊。