|

楼主 |
发表于 2022-7-8 20:12:04
|
显示全部楼层
【花雕体验】16 使用Beetle ESP32 C3控制8X32位WS2812灯板
实验程序二:简单的流水变幻彩虹灯
- /*
- 【花雕体验】16 使用Beetle ESP32 C3控制8X32位WS2812灯板
- 实验程序二:简单的流水变幻彩虹灯
- */
- #include <Adafruit_NeoPixel.h>
- #define PIN 6
- #define BRIGHTNESS 128
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(BRIGHTNESS, PIN, NEO_GRB + NEO_KHZ800);
- void setup() {
- strip.setBrightness(BRIGHTNESS);
- strip.begin();
- strip.show();
- }
- void loop() {
- colorWipe(strip.Color(40, 0, 0), 20); // Red
- colorWipe(strip.Color(0, 40, 0), 20); // Green
- colorWipe(strip.Color(0, 0, 50), 20); // Blue
- colorWipe(strip.Color(40, 40, 50), 20); // BlueWite
- rainbowCycle(1);
- }
- void colorWipe(uint32_t c, uint8_t wait) {
- for (uint16_t i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
- void rainbow(uint8_t wait) {
- uint16_t i, j;
- for (j = 0; j < 256; j++) {
- for (i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, Wheel((i + j) & 255 ));
- }
- strip.show();
- delay(wait);
- }
- }
- void rainbowCycle(uint8_t wait) {
- uint16_t i, j;
- for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
- for (i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
- }
- strip.show();
- delay(wait);
- }
- }
- uint32_t Wheel(byte WheelPos) {
- if (WheelPos < 85) {
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- } else if (WheelPos < 170) {
- WheelPos -= 85;
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- } else {
- WheelPos -= 170;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- }
复制代码
|
|