【花雕动手做】有趣好玩的音乐可视化项目(11)---WS2812幻彩LED灯带
实验程序二:阙值触发的节奏灯
/*
【花雕动手做】有趣好玩的音乐可视化项目(11)---WS2812幻彩LED灯带
实验程序二:阙值触发的节奏灯
*/
#include<FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 24
CRGB leds[NUM_LEDS];
uint8_t hue = 0;
int soundsensor = 7;
void setup() {
delay(2000);
Serial.begin(9600);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
pinMode(soundsensor, INPUT);
}
void loop() {
int sensval = digitalRead(soundsensor);
if (sensval == 1) {
Serial.println("ON");
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++;
}
}
|