#include //FastLED library #define NUM_LED 150 //number of LEDs in the strip #define LED_PIN 5 //data pin on the arduino #define BRIGHTNESS 255 //default brightness #define updateLEDS 5 //number of LEDs to update CRGB led[NUM_LED]; //array of LEDs const int brightnessPot = A1; //pin for the brightness pot const int audioSignal = A0; //pin for the audio signal int volumeLevel; //iniger for volume level void setup() { pinMode(audioSignal, INPUT); //input pin for the audio signal Serial.begin(9600); //serial for debugging FastLED.addLeds(led, NUM_LED); //fastLED initalization FastLED.setBrightness(BRIGHTNESS); //set the default brightness delay(1000); //wait 1 sec resetLedState(); //turn off all the leds } void setLedBrightness() { //function to set the brigthess set on the pot LEDS.setBrightness(map(analogRead(brightnessPot),0,1023,0,255)); } void loop() { setLedBrightness(); //set the new brightness, you can comment this line at the beginning to disable it audioRead(); //reap the audio level and map it Serial.println(volumeLevel); //Send volume level to the serial monitor, you can also use serial plotter to better see the values and adjust the ampplification of the audio signal //for loop to move all the LEDs down the strip for (int i = NUM_LED - 1; i >= updateLEDS; i--) { led[i] = led[i - updateLEDS]; } //for loop to set the first LED corresponding to the audio level for (int i = 0; i < updateLEDS; i++) { displayFilter(volumeLevel, i); //set the right colour magic } FastLED.show(); //updates the LED strip delay(20); //delay } void resetLedState() { //function to turn off all the LEDs for (int turnMeOff = 0; turnMeOff < 61; turnMeOff++) { led[turnMeOff] = CRGB(0, 0, 0); } FastLED.show(); } void audioRead() { //function to read the audio int rawValue = analogRead(audioSignal) * 2; //double the audio level volumeLevel = map(rawValue, 0, 1023, 0, 900); //map it to 900 values if (volumeLevel > 900) { //if it's higher than 900 it lowers it back to 900 volumeLevel = 900; } } /* * a lot of IF statements to set the right color. * colors go from red to blue, then green and orange at the end(red is already used), at 0 volume leds are off/black, at 900/max they're white */ void displayFilter(int volume, int lucka) { if (volume < 1) { led[lucka] = CRGB(0, 0, 0); //0, black } if (volume > 1 && volume < 51) { led[lucka] = CRGB(255, 0, 0); //1-50 } if (volume > 50 && volume < 101) { led[lucka] = CRGB(255, 0, 85); //51-100 } if (volume > 100 && volume < 151) { led[lucka] = CRGB(255, 0, 170); //101-150 } if (volume > 150 && volume < 201) { led[lucka] = CRGB(255, 0, 255); //151-200 } if (volume > 200 && volume < 251) { led[lucka] = CRGB(170, 0, 255); //201-250 } if (volume > 250 && volume < 301) { led[lucka] = CRGB(85, 0, 255); //251-300 } if (volume > 300 && volume < 351) { led[lucka] = CRGB(0, 0, 255); //301-350 } if (volume > 350 && volume < 401) { led[lucka] = CRGB(0, 85, 255); //351-400 } if (volume > 400 && volume < 451) { led[lucka] = CRGB(0, 170, 255); //401-450 } if (volume > 450 && volume < 501) { led[lucka] = CRGB(0, 255, 255); //451-500 } if (volume > 500 && volume < 551) { led[lucka] = CRGB(0, 255, 170); //501-550 } if (volume > 550 && volume < 601) { led[lucka] = CRGB(0, 255, 85); //551-600 } if (volume > 600 && volume < 651) { led[lucka] = CRGB(0, 255, 0); //601-650 } if (volume > 650 && volume < 701) { led[lucka] = CRGB(85, 255, 0); //651-700 } if (volume > 700 && volume < 751) { led[lucka] = CRGB(170, 255, 0); //701-750 } if (volume > 750 && volume < 801) { led[lucka] = CRGB(255, 255, 0); //751-800 } if (volume > 800 && volume < 851) { led[lucka] = CRGB(255, 170, 0); //801-850 } if (volume > 850 && volume < 900) { led[lucka] = CRGB(255, 85, 0); //851-899 } if (volume > 899) { led[lucka] = CRGB(255, 255, 255); //900, white } }