Last active
July 29, 2020 05:35
-
-
Save ghostoy/fd1b285792fb3be893f859228a9cf676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FastLED.h> | |
// 灯带尚灯珠的而数量 | |
#define NUM_LEDS 8 | |
// 控制引脚 | |
#define DATA_PIN 3 | |
// 时钟引脚,对于WS2812来说不需要 | |
#define CLOCK_PIN 13 | |
// 定义每个灯珠的颜色 | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // NEOPIXEL是指代的是WS2812控制芯片,使用GRB颜色顺序,等价于下一行 | |
// FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); | |
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // 另一种WS2812B芯片,RGB颜色顺序 | |
// ## Clocked (SPI) types ## | |
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // WS2801使用SPI协议控制,需要指定时钟 | |
} | |
void loop() { | |
// 所有灯珠调成红色 | |
for (int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CRGB::Red; | |
} | |
// 显示 | |
FastLED.show(); | |
delay(500); | |
// 关闭灯珠 | |
for (int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CRGB::Black; | |
} | |
// 显示 | |
FastLED.show(); | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment