source code
#include
#define LED_PIN 3
#define NUM_LEDS 6
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];
int soundDetectedPin = 10; // Use Pin 10 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound
//Measurement
boolean bAlarm = false;
unsigned long lastSoundDetectTime; // Record the time that we
//measured a sound
int soundAlarmTime = 500; // Number of milli seconds to keep the
//sound alarm high
void setup() {
Serial.begin(9600);
pinMode(soundDetectedPin, INPUT); // input from the Sound
//Detection Module
FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
soundDetectedVal = digitalRead(soundDetectedPin); // read the
//sound alarm time
if (soundDetectedVal == LOW) // If we hear a sound
{
lastSoundDetectTime = millis(); // record the time of the sound
//alarm
// The following is so you don't scroll on the output screen
if (!bAlarm) {
Serial.println("LOUD, LOUD");
bAlarm = true;
// fill_solid(leds, NUM_LEDS, CHSV(257, 255, 255));
// FastLED.show();
// delay(10);
// leds[0] = CHSV(255, 200, 200);
for (int i = 255; i >= 0; i--) {
fill_solid(leds, NUM_LEDS, CHSV(257, 255, i));
delay(10);
FastLED.show();
}
}
// Fade the LED in and out
// for (int i = 0; i < 256; i++) {
// CRGB col = CRGB(i, i, i);
// fill_solid(leds, NUM_LEDS, col);
// }
} else {
if ((millis() - lastSoundDetectTime) > soundAlarmTime && bAlarm) {
Serial.println("quiet");
bAlarm = false;
// // Fade the LED in and out
// // leds[0] = CHSV(255, 0, 0);
fill_solid(leds, NUM_LEDS, CHSV(170, 0, 0));
FastLED.show();
delay(10);
}
}