#include <FastLED.h>
int sound_value;
#define NUM_LEDS 30 //燈珠數
#define LED_PIN 2
#define ANALOG_READ 35
CRGB leds[NUM_LEDS];
void setup(){
Serial.begin(9600);
FastLED.setBrightness(30);
FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds, NUM_LEDS);
}
void loop() {
sound_value = analogRead(ANALOG_READ);
if(sound_value > 2000 && sound_value < 2200){
for (int i = 0; i <= 10; i++)
leds[i] = CRGB(255, 0, 0); //五分之一的燈珠綠光
for (int j = 11; j <= NUM_LEDS; j++)
leds[j] = CRGB(0, 0, 0);
FastLED.show();
delay(15);
}
if(sound_value > 2400 && sound_value < 2600){
for (int i = 0; i <= 18; i++)
leds[i] = CRGB(0, 0, 255); //五分之二的燈珠藍光
for (int j = 19; j <= NUM_LEDS; j++)
leds[j] = CRGB(0, 0, 0);
FastLED.show();
delay(15);
}
if(sound_value > 2800 && sound_value < 3000){
for (int i = 0; i <= 26; i++)
leds[i] = CRGB(0, 125, 125); //五分之三的燈珠紫光
for (int j = 27; j <= NUM_LEDS; j++)
leds[j] = CRGB(0, 0, 0);
FastLED.show();
delay(15);
}
if(sound_value > 3200 && sound_value < 3400){
for (int i = 0; i <= 34; i++)
leds[i] = CRGB(125, 125, 0); //五分之四的燈珠黃光
for (int j = 35; j <= NUM_LEDS; j++)
leds[j] = CRGB(0, 0, 0);
FastLED.show();
delay(15);
}
if(sound_value > 3500){
for (int i = 0; i <= NUM_LEDS; i++)
leds[i] = CRGB(0, 255, 0); //全部紅光
FastLED.show();
delay(5);
}
}
|