【花雕动手做】有趣好玩的音乐可视化系列小项目(18)--LED平面板灯
项目程序之三:FastLED音乐反应节奏灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(18)--LED平面板灯
项目程序之三:FastLED音乐反应节奏灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7
*/
#include<FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 48
CRGB leds[NUM_LEDS];
uint8_t hue = 0;
int soundsensor = 7;
void setup() {
delay(2000);
FastLED.setBrightness(220);
pinMode(soundsensor, INPUT);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
int sensval = digitalRead(soundsensor);
if (sensval == 1) {
leds[0] = CRGB :: Red;
fill_solid(leds, NUM_LEDS, CRGB :: Blue);
rainbow_moving();
FastLED.show();
delay(10);
}
else {
leds[0] = CRGB :: Black;
fill_solid(leds, NUM_LEDS, CRGB :: Black);
FastLED.show();
delay(10);
}
}
void rainbow_moving() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue + (i * 10), 255, 255);
}
EVERY_N_MILLISECONDS(10) {
hue++;
}
}
|