///////////////////////////////////////////////This is the Halloween Test Program for use with the AtmosFX animations for a whole house LED light show 2024///////////////////////////////////////////////////////////////////////// // This sketch is designed for the Animated LED Lighting, LLC Arduino Nano Shield A18804. It samples the frequency signal level measured by the Mixed Signal // Integration MSGEQ7 and converts these values into Pulse Width Modulated (PWM) signals. These PWM signals are fed into the four inputs of the Allegro MicroSystems A80804 LED driver. // The LED driver controls the current through four independent channels of standard RGBW LED light strips. // This progam does not have any code supporting Individually addressable LED light strips // This sketch expects the following pin assignments... // STROBE = DIGITAL 7 // RESET = DIGITAL 8 // OUTPUT = ANALOG 5 ///////////THIS WAS DESIGNED TO WORK FOR THE HALLOWEEN SHOW WITH EMPHASIS ON THE GREEN AND RED LEDS TO MAKE ORANGE AND GREEN THE MOST PROMINANT COLORS. WHITE WORKS WELL FOR LIGHTING STRIKES.//////////////// int strobePin = 7; // Strobe Pin on the MSGEQ7 int resetPin = 8; // Reset Pin on the MSGEQ7 int outPin = A7; // Output Pin on the MSGEQ7 int level[7]; // An array to hold the values from the 7 frequency bands /////////////This is the RGBW pin assignments///////////////////////////////////// int greenPin=6; //pin enabled to supply GREEN LEDs int redPin=9; //pin enabled to supply RED LEDs int bluePin=5; //pin enabled to supply BLUE LEDs int whitePin=3; //pin enable to supply WHITE LEDs int fullPin=2; //need this to keep full pin low unless needed. /////Scale factors in case you wish to lower the value of any one particular color int Rscale=40; int Gscale=10; int Bscale=80; int Wscale=130; int x = 0; int scale=50; // The best setting seems to be 50, this helps to reduce the noise floor int PWMvalue = 0; int dLEDs = (0); // Keep this at zero, adding any delay seems to make it look like the lights are oscillating void setup() { //Serial.begin (9600); //This is used for debugging. Enable this if you wish to view outputs on the serial monitor pinMode(fullPin, OUTPUT); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(whitePin, OUTPUT); // Startup Test Mode, provides an opportunity to check all your lights. Increase the value of i if you need more cycles. Only happens on power up. //Coment this out if you don't want test cycles for (int i=0; i<3; i++){ analogWrite(redPin, 175); delay(1000); analogWrite(redPin, 0); analogWrite(greenPin, 175); delay(1000); analogWrite(greenPin, 0); analogWrite(bluePin, 175); delay(1000); analogWrite(bluePin, 0); analogWrite(whitePin, 175); delay(1000); analogWrite(whitePin, 0); delay(1000); } digitalWrite (fullPin, LOW); //Keep the full pin pulled Low unless we need it. pinMode (strobePin, OUTPUT); pinMode (resetPin, OUTPUT); pinMode (outPin, INPUT); //input from the Audio // Create an initial state for our pins digitalWrite (resetPin, LOW); digitalWrite (strobePin, LOW); delay (1); // Reset the MSGEQ7 as per the datasheet timing diagram digitalWrite (resetPin, HIGH); delay (1); // delay in milliseconds digitalWrite (resetPin, LOW); digitalWrite (strobePin, HIGH); delay (1); } void loop() { digitalWrite (fullPin, LOW); //Keep the full pin pulled Low unless we need it. // Cycle through each frequency band by pulsing the strobe pin. for (int i = 0; i < 7; i++) { digitalWrite (strobePin, LOW); delayMicroseconds (20); // Delay necessary due to timing diagram for MSGEQ7 level[i] = analogRead (outPin); // if (level[i] < scale){ // I added the if statement to wipe out the low end noise floor. // level[i] = 1; // } PWMvalue = map(level[i], 0, 1023, 0, 255); // Map the actual level recorded to the PWM scale of 0 - 255 if (PWMvalue < 50){ // I added the if statement to wipe out the low end noise floor. PWMvalue = 5; } // This section is setup in order of bins, 63Hz, 160Hz, 400Hz, 1000Hz, 2500Hz, 6250Hz and 16000Hz. if(i == 0){ //27Hz - 140Hz , Peak is around 68Hz analogWrite(bluePin, PWMvalue-Bscale); delay(dLEDs); } else if(i == 1){ //96Hz - 160Hz, Peak is around 175Hz analogWrite(whitePin, PWMvalue-Wscale); delay(dLEDs); } else if(i == 2){ //167Hz - 400Hz, Peak is around 470Hz analogWrite(redPin, PWMvalue-Rscale); analogWrite(greenPin, PWMvalue-Gscale); delay(dLEDs); } else if(i == 3){ //417Hz - 1000Hz, Peak is around 1100Hz analogWrite(redPin, PWMvalue-Rscale); delay(dLEDs); } else if(i == 4){ //1700 - 2500Hz, Peak is around 2700Hz //analogWrite(greenPin, PWMvalue-Gscale); analogWrite(bluePin, PWMvalue-Bscale); delay(dLEDs); } else if(i == 5){ //5000 - 6250Hz, Peak is around 9000Hz analogWrite(bluePin, PWMvalue-Bscale); delay(dLEDs); } else if(i == 6){ //12000 - 16000Hz, Peak is around 17000Hz analogWrite(whitePin, PWMvalue-Wscale); delay(dLEDs); } digitalWrite (strobePin, HIGH); delayMicroseconds (20); // Delay necessary due to timing diagram } }