Skip to content

Instantly share code, notes, and snippets.

@ghostoy
Created May 28, 2019 08:29
Show Gist options
  • Save ghostoy/4b7f1789654e782759503c224407e74b to your computer and use it in GitHub Desktop.
Save ghostoy/4b7f1789654e782759503c224407e74b to your computer and use it in GitHub Desktop.
#include <FastLED.h>
// 7个LED灯,如果你的数量不一样改成自己的LED灯数量
#define NUM_LEDS 7
// led控制端口
const int ledPin = 3;
CRGB rainbow[NUM_LEDS] = { CRGB::Red, CRGB::Orange, CRGB::Yellow, CRGB::Green, CRGB::Blue, {0, 0x7f, 0xff}, CRGB::Purple };
CRGB leds[NUM_LEDS];
void setup() {
FastLED.add<NEOPIXEL, ledPin>(leds, NUM_LEDS); // 初始化NEOPIXEL类型的LED灯带
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = rainbow[i]; FastLED.show(); delay(100); // 点亮第i个LED,颜色是rainbow数组里第i个颜色
leds[i] = CRGB::Black; FastLED.show(); delay(100); // 熄灭它
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment