【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序三:256位显示 RGBW 的 WHITE 通道的测试使用
-
-
- #include <Adafruit_NeoPixel.h>
-
- #define LED_PIN 9
- #define LED_COUNT 256
-
- Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
-
- void setup() {
- strip.setBrightness(30);
- strip.begin();
- strip.show();
- }
-
- void loop() {
-
- colorWipe(strip.Color(255, 0, 0) , 50);
- colorWipe(strip.Color( 0, 255, 0) , 50);
- colorWipe(strip.Color( 0, 0, 255) , 50);
- colorWipe(strip.Color( 0, 0, 0, 255), 50);
-
- whiteOverRainbow(75, 5);
-
- pulseWhite(5);
-
- rainbowFade2White(3, 3, 1);
- }
-
-
-
-
-
-
- void colorWipe(uint32_t color, int wait) {
- for (int i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, color);
- strip.show();
- delay(wait);
- }
- }
-
- void whiteOverRainbow(int whiteSpeed, int whiteLength) {
-
- if (whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
-
- int head = whiteLength - 1;
- int tail = 0;
- int loops = 3;
- int loopNum = 0;
- uint32_t lastTime = millis();
- uint32_t firstPixelHue = 0;
-
- for (;;) {
- for (int i = 0; i < strip.numPixels(); i++) {
- if (((i >= tail) && (i <= head)) ||
- ((tail > head) && ((i >= tail) || (i <= head)))) {
- strip.setPixelColor(i, strip.Color(0, 0, 0, 255));
- } else {
- int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
- strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
- }
- }
-
- strip.show();
-
-
-
- firstPixelHue += 40;
-
- if ((millis() - lastTime) > whiteSpeed) {
- if (++head >= strip.numPixels()) {
- head = 0;
- if (++loopNum >= loops) return;
- }
- if (++tail >= strip.numPixels()) {
- tail = 0;
- }
- lastTime = millis();
- }
- }
- }
-
- void pulseWhite(uint8_t wait) {
- for (int j = 0; j < 256; j++) {
-
- strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
- strip.show();
- delay(wait);
- }
-
- for (int j = 255; j >= 0; j--) {
- strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
- strip.show();
- delay(wait);
- }
- }
-
- void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
- int fadeVal = 0, fadeMax = 100;
-
-
-
-
-
- for (uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops * 65536;
- firstPixelHue += 256) {
-
- for (int i = 0; i < strip.numPixels(); i++) {
-
-
-
-
- uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
-
-
-
-
-
- strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
- 255 * fadeVal / fadeMax)));
- }
-
- strip.show();
- delay(wait);
-
- if (firstPixelHue < 65536) {
- if (fadeVal < fadeMax) fadeVal++;
- } else if (firstPixelHue >= ((rainbowLoops - 1) * 65536)) {
- if (fadeVal > 0) fadeVal--;
- } else {
- fadeVal = fadeMax;
- }
- }
-
- for (int k = 0; k < whiteLoops; k++) {
- for (int j = 0; j < 256; j++) {
-
- strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
- strip.show();
- }
- delay(100);
- for (int j = 255; j >= 0; j--) {
- strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
- strip.show();
- }
- }
-
- delay(50);
- }
|