目的:測試 WS2812 LED PCB
板子的選擇如下:
工具🡪開發板🡪Arduino Mbed OS RP2040 borads 🡪 Raspberry Pi Pico
這個選項很重要要非常小心注意
這個是控制四塊PCB的程式
可以成功的運行
如果選擇Raspberry Pi Pico RP2040 如下圖:
同樣的程式compiler 會出現下列錯誤:
原因不明可能是Fastled library 與Raspberry Pi Pico 的底層有不相容吧!!
I/O PORT 規劃表
WS2812 全採LED驅動下面是我寫的範例程式
/// @file ArrayOfLedArrays.ino
/// @brief Set up three LED strips, all running from an array of arrays
/// @example ArrayOfLedArrays.ino
// ArrayOfLedArrays - see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for more info on
// using multiple controllers. In this example, we're going to set up three NEOPIXEL strips on three
// different pins, each strip getting its own CRGB array to be played with, only this time they're going
// to be all parts of an array of arrays.
/*
2024/03/12
程式設計 : 李進衛
發展板: RP2040
機種: LED測試程式
版本:1.0
根據Fastled library 範例修改以符合治具測試使用
這個程式compiler的板子選項要特別注意
在ArduinoIDE中:工具-->開發板-->Arduino Mbed OS RP2040 borads-->Raspberry Pi Pico
才能compiler成功
LED的亮度可以考慮使用VR調節但是這個程式我沒有加入這個功能,開發板的ADC我有預留出來
視狀況加入這個亮度的調節功能
*/
#include <FastLED.h>
#define NUM_STRIPS 4 //四聯板
#define NUM_LEDS_PER_STRIP 60 //每一片板子的LED數
#define BRIGHTNESS 50 //2024/03/07 by 李進衛 modify 60
#define delaytime 25 //50 // delay time
CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP]; //開二維陣列處理LED
// For mirroring strips, all the "special" stuff happens just in setup. We
// just addLeds multiple times, once for each strip
void setup() {
// tell FastLED there's 60 NEOPIXEL leds on pin 3
FastLED.addLeds<WS2812B, 3, GRB>(leds[0], NUM_LEDS_PER_STRIP);
// tell FastLED there's 60 NEOPIXEL leds on pin 4
FastLED.addLeds<WS2812B, 4, GRB>(leds[1], NUM_LEDS_PER_STRIP);
// tell FastLED there's 60 NEOPIXEL leds on pin 5
FastLED.addLeds<WS2812B, 5, GRB>(leds[2], NUM_LEDS_PER_STRIP);
// tell FastLED there's 60 NEOPIXEL leds on pin 6
FastLED.addLeds<WS2812B, 6, GRB>(leds[3], NUM_LEDS_PER_STRIP);
}
void loop() {
// This outer loop will go over each strip, one at a time
FastLED.setBrightness(BRIGHTNESS);
for(int x = 0; x < NUM_STRIPS; x++) {
// This inner loop will go over each led in the current strip, one at a time
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
leds[x][i] = CRGB::White; //Red;
FastLED.show();
// leds[x][i] = CRGB::Black;
delay(delaytime);
}
for(int i = NUM_LEDS_PER_STRIP; i>=0; i--) {
leds[x][i] = CRGB::Red;
FastLED.show();
// leds[x][i] = CRGB::Black;
delay(delaytime);
}
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
leds[x][i] = CRGB::Green; //Red;
FastLED.show();
// leds[x][i] = CRGB::Black;
delay(delaytime);
}
for(int i = NUM_LEDS_PER_STRIP; i>=0; i--) {
leds[x][i] = CRGB::Blue;
FastLED.show();
// leds[x][i] = CRGB::Black;
delay(delaytime);
}
}
}
沒有留言:
張貼留言