Max9814 Microphone Amplifier Agc Auto Gain Control
Rs. 119.00 Rs. 143.00
- Brand: https://www.maximintegrated.com/en/products/analog/audio/MAX9814
- Product Code: SEN-MICROPHONE
- SKU -
- Availability: In Stock
- Price in reward points: 2
- For Bulk Order 9962060070
Quick support on WhatsApp (+919962060070) only between morning 11am-4pm, no call will be answered
SPECIFICATIONS: | |
Supply Voltage | 2.7v-5.5v @ 3mA current |
Output | 2Vpp on 1.25V bias |
Frequency Response | 20Hz – 20 KHz |
Programmable Attack and Release | Ratio |
Automatic gain, selectable max from | 40dB, 50dB or 60dB |
Low Input-Referred Noise Density of | 30nV/ |
Low THD | 0.04% (typ) |
OVERVIEW:
-Automatic Gain Control (AGC)
-Three Gain Settings (40dB, 50dB, 60dB)
-Programmable Attack Time
-Programmable Attack and Release Ratio
-2.7V to 5.5V Supply Voltage Range
-Low Input-Referred Noise Density of 30nV/√Hz
-Low THD: 0.04% (typ)
-Low-Power Shutdown Mode
-Internal Low-Noise Microphone Bias, 2V
-Available in the Space-Saving, 14-Pin TDFN (3mm
-x 3mm) Package
--40°C to +85°C Extended Temperature Range
PACKAGE INCLUDES:
1 PCS x Max9814 Microphone Amplifier Agc Auto Gain Control
https://www.maximintegrated.com/en/products/analog/audio/MAX9814.html
//SOURCE CODE TAKEN FROM BELOW LINK
//https://www.instructables.com/Arduino-Controlled-Sound-Responsive-LED-Display/
//Please note this is a horribly hacked together example of 'just about' working code. If you think you can do better, you probably can.
//************
//Sound Level to light show sketch for the
//autogain microphone Amplifier from Adafruit on pin AO
//plus neopixel led functions (pin 6) mapped on to different sound levels to give music to light effects
//
//*************
//lines below set variables for neopixels
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#define NUMBER_PIXEL 32
#define LED_PIN 6
#define NUM_LEDS 32
#define LEDTYPE WS2812B
#define COLOR_ORDER GRB
#define LED_HALF NUM_LEDS/2
#define VISUALS 6 //Change this accordingly if you add/remove a visual in the switch-case in Visualize()
#define AUDIO_PIN A1 //Pin for the envelope of the sound detector
#define KNOB_PIN A3 //Pin for the trimpot 10K
#define DC_OFFSET 1.25 // DC offset in mic signal - if unusure, leave 0
#define NOISE 260 // Noise/hum/interference in mic signal
#define SAMPLES 40 // Length of buffer for dynamic level adjustment
#define TOP (NUMBER_PIXEL + 2) // Allow dot to go slightly off scale
#define PEAK_FALL 60 // Rate of peak falling dot
const int buttonPin = 9;
int buttonState = 0;
int buttonPushCounter = 0;
int lastButtonState = 0;
int lng = 100;//long delay
int sht = 50;//short delay
byte
peak = 0, // Used for falling dot
dotCount = 0, // Frame counter for delaying dot-falling speed
volCount = 0; // Frame counter for storing past volume data
int
vol[SAMPLES], // Collection of prior volume samples
lvl = 0, // Current "dampened" audio level
minLvlAvg = 0, // For dynamic adjustment of graph low & high
maxLvlAvg = 512;
CRGB leds[NUM_LEDS];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMBER_PIXEL, LED_PIN, NEO_GRB + NEO_KHZ800);
//////////<Globals>
// These values either need to be remembered from the last pass of loop() or
// need to be accessed by several functions in one pass, so they need to be global.
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); //LED strip objetcs
uint16_t gradient = 0; //Used to iterate and loop through each color palette gradually
//IMPORTANT:
// This array holds the "threshold" of each color function (i.e. the largest number they take before repeating).
// The values are in the same order as in ColorPalette()'s switch case (Rainbow() is first, etc). This is simply to
// keep "gradient" from overflowing, the color functions themselves can take any positive value. For example, the
// largest value Rainbow() takes before looping is 1529, so "gradient" should reset after 1529, as listed.
// Make sure you add/remove values accordingly if you add/remove a color function in the switch-case in ColorPalette().
uint16_t thresholds[] = {1529, 1019, 764, 764, 764, 1274};
uint8_t palette = 0; //Holds the current color palette.
uint8_t visual = 0; //Holds the current visual being displayed.
uint8_t volume = 0; //Holds the volume level read from the sound detector.
uint8_t last = 0; //Holds the value of volume from the previous loop() pass.
uint8_t x = 0;
float maxVol = 5; //Holds the largest volume recorded thus far to proportionally adjust the visual's responsiveness.
float knob = 1023.0; //Holds the percentage of how twisted the trimpot is. Used for adjusting the max brightness.
float avgBump = 0; //Holds the "average" volume-change to trigger a "bump."
float avgVol = 0; //Holds the "average" volume-level to proportionally adjust the visual experience.
float shuffleTime = 0; //Holds how many seconds of runtime ago the last shuffle was (if shuffle mode is on).
//lines below are for the microphone sampling from Adafruit autogain mic
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//NOTE: The reason "average" is quoted is because it is not a true mathematical average. This is because I have
// found what I call a "sequenced average" is more successful in execution than a real average. The difference
// is that the sequenced average doesn't use the pool of all values recorded thus far, but rather averages the
// last average and the current value received (in sequence). Concretely:
//
// True average: (1 + 2 + 3) / 3 = 2
// Sequenced: (1 + 2) / 2 = 1.5 --> (1.5 + 3) / 2 = 2.25 (if 1, 2, 3 was the order the values were received)
//
// All "averages" in the program operate this way. The difference is subtle, but the reason is that sequenced
// averages are more adaptive to changes in the overall volume. In other words, if you went from loud to quiet,
// the sequenced average is more likely to show an accurate and proportional adjustment more fluently.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool shuffle = true; //Toggles shuffle mode.
bool bump = false; //Used to pass if there was a "bump" in volume
//For Traffic() visual
int8_t pos[NUM_LEDS] = { -2}; //Stores a population of color "dots" to iterate across the LED strip.
uint8_t rgb[NUM_LEDS][3] = {0}; //Stores each dot's specific RGB values.
//For Snake() visual
bool left = false; //Determines the direction of iteration. Recycled in PaletteDance()
int8_t dotPos = 0; //Holds which LED in the strip the dot is positioned at. Recycled in most other visuals.
float timeBump = 0; //Holds the time (in runtime seconds) the last "bump" occurred.
float avgTime = 0; //Holds the "average" amount of time between each "bump" (used for pacing the dot's movement).
//////////</Globals>
void setup()
{
strip.begin();//initialises neopixels
strip.setBrightness(255);// set brightness from 0 to max is 255
strip.show();//clears any previous data in the strip
//strip.begin(); //Initialize the LED strip object.
//strip.show(); //Show a blank strip, just to get the LED's ready for use.
Serial.begin(9600);//set up for checking mic is working
//Serial.println("mood FastLED WS2812B");
//Serial.println("https://codebender.cc/sketch:220829");
//delay(3000); //safety startup delay to protect LEDS
memset(vol, 0, sizeof(vol));
strip.begin();
pinMode(buttonPin, INPUT);
FastLED.addLeds<LEDTYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
if (buttonPushCounter >= 5) {
buttonPushCounter = 0;
}
delay(250);
}
lastButtonState = buttonState;
}
if (buttonPushCounter == 1)
{
static uint8_t hue = 170; // start at blue
FastLED.showColor(CHSV(hue++, 255, 191)); // loop trough all the hue colors
//FastLED.delay(300); // FastLED2.1 has a bug
Serial.println(hue);
delay(300);
}
else if (buttonPushCounter == 2)
{
//This is where the magic happens. This loop produces each frame of the visual.
//open void loop
//first run the sound sampling
unsigned long startMillis = millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
//open while loop
sample = analogRead(AUDIO_PIN);
if (sample < 1024) // toss out spurious readings
{
//open 1st if loop in while
if (sample > signalMax)
{
//open 2nd if
signalMax = sample; // save just the max levels
}//close 2nd if
else if (sample < signalMin)
{
//open 3rd if
signalMin = sample; // save just the min levels
}//close 3rd if
}//close 1st if
}//close while loop
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 3.3) / 1024; // convert to volts
//Serial.println(volts);
int sound = (volts * 10);
//Serial.println(sound);
volume = map(sound, 1, 10, 0, 255);
//Serial.println(volume);
//Serial.println(volume);
// knob = 1023.5 / 1023.0;//
knob = analogRead(KNOB_PIN) ;// 1023.0; //Record how far the trimpot is twisted
//Sets a threshold for volume.
// In practice I've found noise can get up to 15, so if it's lower, the visual thinks it's silent.
// Also if the volume is less than average volume / 2 (essentially an average with 0), it's considered silent.
if (volume < avgVol / 2.0 || volume < 15) volume = 0;
else avgVol = (avgVol + volume) / 2.0; //If non-zeo, take an "average" of volumes.
//If the current volume is larger than the loudest value recorded, overwrite
if (volume > maxVol) maxVol = volume;
//Check the Cycle* functions for specific instructions if you didn't include buttons in your design.
////////////////////////////////////////////////////////////////////////////////////////////////////
CyclePalette(); //Changes palette for shuffle mode or button press.
CycleVisual(); //Changes visualization for shuffle mode or button press.
//ToggleShuffle(); //Toggles shuffle mode. Delete this if you didn't use buttons.
////////////////////////////////////////////////////////////////////////////////////////////////////
//This is where "gradient" is modulated to prevent overflow.
if (gradient > thresholds[palette]) {
gradient %= thresholds[palette] + 1;
//Everytime a palette gets completed is a good time to readjust "maxVol," just in case
// the song gets quieter; we also don't want to lose brightness intensity permanently
// because of one stray loud sound.
maxVol = (maxVol + volume) / 2.0;
}
//If there is a decent change in volume since the last pass, average it into "avgBump"
if (volume - last > 10) avgBump = (avgBump + (volume - last)) / 2.0;
//If there is a notable change in volume, trigger a "bump"
// avgbump is lowered just a little for comparing to make the visual slightly more sensitive to a beat.
bump = (volume - last > avgBump * .9);
//If a "bump" is triggered, average the time between bumps
if (bump) {
avgTime = (((millis() / 1000.0) - timeBump) + avgTime) / 2.0;
timeBump = millis() / 1000.0;
}
Visualize(); //Calls the appropriate visualization to be displayed with the globals as they are.
gradient++; //Increments gradient
last = volume; //Records current volume for next pass
delay(30); //Paces visuals so they aren't too fast to be enjoyable
}
else if (buttonPushCounter == 3)
{
uint8_t i;
uint16_t minLvl, maxLvl;
int n, height;
n = analogRead(AUDIO_PIN); // Raw reading from mic
n = abs(n - 512 - DC_OFFSET); // Center on zero
n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum
lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy)
// Calculate bar height based on dynamic min/max levels (fixed point):
height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
if(height < 0L) height = 0; // Clip output
else if(height > TOP) height = TOP;
if(height > peak) peak = height; // Keep 'peak' dot at top
// Color pixels based on rainbow gradient
for(i=0; i<NUMBER_PIXEL; i++) {
if(i >= height) strip.setPixelColor(i, 0, 0, 0);
else strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150)));
}
// Draw peak dot
if(peak > 0 && peak <= NUMBER_PIXEL-1) strip.setPixelColor(peak,Wheel(map(peak,0,strip.numPixels()-1,30,150)));
strip.show(); // Update strip
// Every few frames, make the peak pixel drop by 1:
if(++dotCount >= PEAK_FALL) { //fall rate
if(peak > 0) peak--;
dotCount = 0;
}
vol[volCount] = n; // Save sample for dynamic leveling
if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
// Get volume range of prior frames
minLvl = maxLvl = vol[0];
for(i=1; i<SAMPLES; i++) {
if(vol[i] < minLvl) minLvl = vol[i];
else if(vol[i] > maxLvl) maxLvl = vol[i];
}
if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
}
else if (buttonPushCounter == 4)
{rainbowCycle(3);//from the neopixel library
}
else
{
//open void loop
//first run the sound sampling
unsigned long startMillis = millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
//open while loop
sample = analogRead(AUDIO_PIN);
if (sample < 1024) // toss out spurious readings
{
//open 1st if loop in while
if (sample > signalMax)
{
//open 2nd if
signalMax = sample; // save just the max levels
}//close 2nd if
else if (sample < signalMin)
{
//open 3rd if
signalMin = sample; // save just the min levels
}//close 3rd if
}//close 1st if
}//close while loop
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 3.3) / 1024; // convert to volts
//Serial.println(volts);
//section below maps the signal from the microphone on to 12 options for LED effects
int sound = (volts * 10);
//Serial.println(sound);
int soundLevel = map(sound, 1, 10, 0, 11);
//Serial.print("The volt level is ");
Serial.println(volts);//for debugging
//next section is a series of 12 (0-11) 'if' statements which trigger different patterns.
//it is a combination of a traditional VU style meter fill of the strip
// combined with randomised animated patterns to keep it interesting
if (soundLevel == 0)
{
//open if 0. When there is silence a rainbow pattern runs
rainbowCycle(3);//from the neopixel library
}//close if 0 statement
if (soundLevel == 1)
{
//open level 1 if statement which contains 4 randomised options
int level1Color = random(1, 4);//choose random number 1 - 4
if (level1Color == 1) //if random no 1 chosen light up pixels 1 and 2 red:
{
strip.setPixelColor(0, 255, 0, 0); // this turns on pixel 1 100% red (range runs 0 - 255) and leaves green and blue off
strip.setPixelColor(1, 255, 0, 0); // - you get the idea
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close red random no. 1
else if (level1Color == 2) //if random no 2 choses show green
{
strip.setPixelColor(0, 0, 255, 0);
strip.setPixelColor(1, 0, 255, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close random no. 2 green
else if (level1Color == 3) //run blue
{
strip.setPixelColor(0, 0, 0, 255);
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close blue
else if (level1Color == 4) //run yellow
{
strip.setPixelColor(0, 255, 255, 0);
strip.setPixelColor(1, 255, 255, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close yellow
}//end of if sound level 1 options
if (soundLevel == 2)
{
//open level 2
int level2Color = random(1, 5);//choose one of 5 options if sound level 2
if (level2Color == 1) //run red mix
{
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(2, 255, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 1 red
else if (level2Color == 2) //run green mix
{
//open option 2
strip.setPixelColor(0, 0, 206, 209);
strip.setPixelColor(1, 0, 206, 209);
strip.setPixelColor(2, 0, 206, 209);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close green
else if (level2Color == 3) //run blue mix
{
//open option 3
strip.setPixelColor(0, 0, 0, 255);
strip.setPixelColor(1, 255, 0, 0);
strip.setPixelColor(2, 0, 0, 255);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 3 blue
else if (level2Color == 4) //run yellow
{
//open option 4
strip.setPixelColor(0, 255, 255, 0);
strip.setPixelColor(1, 255, 255, 0);
strip.setPixelColor(2, 255, 255, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close yellow
else if (level2Color == 5)//for a bit of variation 1 in 5 of level 2 will show a pattern across whole strip:
{
//open if 5
strip.setPixelColor(0, 200, 75, 109);
strip.setPixelColor(1, 252, 203, 198);
strip.setPixelColor(2, 255, 216, 209);
strip.setPixelColor(3, 253, 215, 130);
strip.setPixelColor(4, 181, 198, 130);
strip.setPixelColor(5, 141, 189, 193);
strip.setPixelColor(6, 177, 217, 242);
strip.setPixelColor(7, 100, 165, 187);
strip.setPixelColor(8, 133, 105, 128);
strip.setPixelColor(9, 140, 166, 95);
strip.setPixelColor(10, 198, 44, 58);
strip.setPixelColor(11, 149, 69, 103);
strip.show();
delay(lng);
strip.setPixelColor(1, 200, 75, 109);
strip.setPixelColor(2, 252, 203, 198);
strip.setPixelColor(3, 255, 216, 209);
strip.setPixelColor(4, 253, 215, 130);
strip.setPixelColor(5, 181, 198, 130);
strip.setPixelColor(6, 141, 189, 193);
strip.setPixelColor(7, 177, 217, 242);
strip.setPixelColor(8, 100, 165, 187);
strip.setPixelColor(9, 133, 105, 128);
strip.setPixelColor(10, 140, 166, 95);
strip.setPixelColor(11, 198, 44, 58);
strip.setPixelColor(0, 149, 69, 103);
strip.show();
delay(lng);
}//close of option 5
}//close level 2
if (soundLevel == 3)
{
//open if sound level 3
int level3Color = random(1, 5);
if (level3Color == 1) //run red
{
//open option 1
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 0, 255, 0);
strip.setPixelColor(2, 255, 0, 0);
strip.setPixelColor(3, 0, 255, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 1 red
else if (level3Color == 2) //run green
{
//open option 2
strip.setPixelColor(0, 245, 116, 97);
strip.setPixelColor(1, 169, 221, 20);
strip.setPixelColor(2, 245, 116, 97);
strip.setPixelColor(3, 169, 221, 20);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 2green
else if (level3Color == 3) //run blue
{
//open option 3
strip.setPixelColor(0, 169, 221, 199);
strip.setPixelColor(1, 245, 116, 97);
strip.setPixelColor(2, 169, 221, 199);
strip.setPixelColor(3, 245, 116, 97);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 3 blue
else if (level3Color == 4) //run yellow
{
//open option 4
strip.setPixelColor(0, 255, 255, 0);
strip.setPixelColor(1, 255, 255, 0);
strip.setPixelColor(2, 255, 255, 0);
strip.setPixelColor(3, 255, 255, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 4 yellow
else if (level3Color == 5)
{
//open option 5
strip.setPixelColor(0, 255, 255, 255);
strip.setPixelColor(1, 255, 105, 180);
strip.setPixelColor(2, 255, 255, 255);
strip.setPixelColor(3, 255, 105, 180);
strip.setPixelColor(4, 255, 255, 255);
strip.setPixelColor(5, 255, 105, 180);
strip.setPixelColor(6, 255, 255, 255);
strip.setPixelColor(7, 255, 105, 180);
strip.setPixelColor(8, 255, 255, 255);
strip.setPixelColor(9, 255, 105, 180);
strip.setPixelColor(10, 255, 255, 255);
strip.setPixelColor(11, 255, 105, 180);
strip.show();
delay(sht);
}//close of option 5
}//close level 3
if (soundLevel == 4)
{
//open if sound level 4
int level4Color = random(1, 5);
if (level4Color == 1) //run red
{
//open option 1
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(2, 255, 0, 0);
strip.setPixelColor(3, 0, 0, 255);
strip.setPixelColor(4, 255, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close red
else if (level4Color == 2) //run green
{
//open option 2
strip.setPixelColor(0, 0, 255, 0);
strip.setPixelColor(1, 0, 255, 0);
strip.setPixelColor(2, 0, 255, 0);
strip.setPixelColor(3, 0, 255, 0);
strip.setPixelColor(4, 0, 255, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close green
else if (level4Color == 3) //run blue
{
//open option 3
strip.setPixelColor(0, 0, 0, 255);
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(2, 0, 0, 255);
strip.setPixelColor(3, 0, 0, 255);
strip.setPixelColor(4, 0, 0, 255);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close blue
else if (level4Color == 4) //run yellow
{
//open option 4
strip.setPixelColor(0, 255, 255, 0);
strip.setPixelColor(1, 255, 255, 0);
strip.setPixelColor(2, 255, 255, 0);
strip.setPixelColor(3, 255, 255, 0);
strip.setPixelColor(4, 255, 255, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close yellow
else if (level4Color == 5)
{
////open option 5
strip.setPixelColor(0, 255, 01, 165);
strip.setPixelColor(1, 255, 187, 218);
strip.setPixelColor(2, 228, 194, 191);
strip.setPixelColor(3, 153, 87, 205);
strip.setPixelColor(4, 176, 284, 218);
strip.setPixelColor(5, 67, 142, 200);
strip.setPixelColor(6, 107, 167, 214);
strip.setPixelColor(7, 168, 204, 232);
strip.setPixelColor(8, 59, 198, 182);
strip.setPixelColor(9, 100, 212, 199);
strip.setPixelColor(10, 164, 231, 223);
strip.setPixelColor(11, 176, 124, 218);
strip.show();
delay(lng);
}//close option 5
}//close if sound level 4
else if (soundLevel == 5)
{
//open if sound level 5
int level5Color = random(1, 6);
if (level5Color == 1) //run red
{
//open option 1
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 255, 255, 255);
strip.setPixelColor(2, 0, 0, 255);
strip.setPixelColor(3, 255, 0, 0);
strip.setPixelColor(4, 255, 255, 255);
strip.setPixelColor(5, 0, 0, 255);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.show();
delay(lng);
}//close option 1 red
else if (level5Color == 2) //run green
{
//open option 2
strip.setPixelColor(0, 0, 255, 0);
strip.setPixelColor(1, 0, 255, 0);
strip.setPixelColor(2, 0, 255, 0);
strip.setPixelColor(3, 0, 255, 0);
&n
15 days