Components and supplies
JST Connectors and Crimper (optional)
Neoprene Tubing, 12mm internal diameter, cut length to fit LED strip
Pre-perforated Prototype Board, 3cm x 7cm min.
Switch SPST or SPDT
Arduino Nano Every
Potentiometer 10k ohm
Wall Adapter 9vdc
Capacitor 100 nF
Barrel Connector for Wall Adapter
Audio Connector, 3.5mm stereo, panel mount
Resistor 100k ohm
Audio Cable
Audio Y Adapter
Junction Box, 158 x 90 x 60 mm
Resistor 4.7k ohm
Addressable RGB LED Strip, 29 LEDs are needed for this project
Aluminum Bar, 1/2"x1/8", cut length to fit LED strip
Resistor 10k ohm
Buck Converter 9vdc to 5vdc
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Arduino Sketch
arduino
1#include "Adafruit_NeoPixel.h" 2#include <arduinoFFT.h> 3 4//LED STRIP VARIABLES 5int leds=29; //number of LEDs in strip 6int brightness=64; //overall brightness level of entire strip, 0 (off) to 255 7int sat=255; //saturation from 0(grayscale) to 255(max sat.) 8int val=64; //value (individual brightness) from 0(off) to 255(max) 9int valMax=255; //max value of individual led brightness 10uint32_t rgbColour; //used to convert HSV colour to RGB colour 11long hueBottom; //hue value for top LED, selected with pot at hueBottomPin 12long hueBottomMapped; //mapped to hueMin, hueMax range 13long hueTop; //hue value for bottom LED, selected with pot at hueBottomPin 14long hueTopMapped; //mapped to hueMin, hueMax range 15long hueStep; //hue range (mapped) per led 16long hue=43691; //calculated final hue value, from 65536(violet) to 0(red) 17float k; //steepness of s-curve, read from k Pot as 0-1023 18long hueSig[29]; //array to store hue (with s-curve applied) for each LED 19long hueMin=0; //min possible hue: red 20long hueMax=65536; //max possible hue: violet 21int ledPin=3; //digital output pin to LED strip 22int modeSwitchPin=2; //digital input pin for FFT/Colour Set switch 23int audioPin=A0; //audio input pin 24int satPin=A2; //saturation potentiometer pin 25int brightnessPin=A1; //overall brightness potentiometer pin 26int hueTopPin=A3; //top hue potentiometer pin 27int hueBottomPin=A4; //bottom hue potentiometer pin 28int kPin=A5; //s-curve steepness (k) potentiometer pin 29 30Adafruit_NeoPixel strip = Adafruit_NeoPixel(leds, ledPin, NEO_GRB + NEO_KHZ800); 31 32//FFT VARIABLES 33const int bands=32; //total number of frequency bands, must be <= SAMPLES/2 34const int SAMPLES=64; //2x the number of freq bands. Must be a power of 2 35const int audioIn=A0; //audio input is analog pin A0 36double vReal[SAMPLES]; 37double vImag[SAMPLES]; 38arduinoFFT FFT = arduinoFFT(); //creates an FFT object 39 40//This function causes the Nano to reset. It is necessary to initiate the Colour Set mode. 41void(* resetFunc) (void) = 0; 42 43void setup() { 44 pinMode(modeSwitchPin,INPUT); //set modeSwitchPin as input 45 delay(3000); //power-up safety delay 46 strip.begin(); //initialize LED strip 47 strip.show(); //initialize all pixels 48} 49 50void loop() { 51 52 //While mode switch is low, set colours. Otherwise, perform FFT. 53 while (digitalRead(modeSwitchPin)==LOW){ 54 55 //analogRead gives 0-1023 & brightness requires 1-255, so divide reading by 4 56 brightness=analogRead(brightnessPin)/4; //read brightness pot 57 strip.setBrightness(brightness); // set overall brightness 58 //analogRead gives 0-1023 & sat requires 1-255, so divide reading by 4 59 sat=analogRead(satPin)/4; //read brightness pot 60 //read hueTop & hueBottom pots. analogRead gives 0-1023 61 hueBottom=analogRead(hueBottomPin); //read hueBottom pot, 0-1023 62 hueBottomMapped=map(hueBottom,0,1023,hueMin,hueMax); 63 hueTop=analogRead(hueTopPin); //read hueTop pot, 0-1023 64 hueTopMapped=map(hueTop,0,1023,hueMin,hueMax); 65 hueStep=(hueTopMapped-hueBottomMapped)/leds; 66 k=analogRead(kPin); //read k pot, 0-1023 67 68 for (int i=0;i<leds;i++) { 69 hue = hueBottomMapped+(i*hueStep); //calculate hue for each of the LEDs 70 Serial.print ("hue: "); 71 Serial.print (hue); 72 hueSig[i] = hueMax/(1+(pow(2.718,(0-(k/4000000))*(hue-(hueMax/2))))); //apply s-curve 73 Serial.print ("hueSig: "); 74 Serial.println (hueSig[i]); 75 rgbColour = strip.ColorHSV(hueSig[i],sat,val); //calculate colour setting from HSV values 76 strip.setPixelColor(i,rgbColour); //output RGB colour setting to LED 77 strip.show(); //show the colour 78 delay(10); 79 } 80 } 81 82 //FFT sampling 83 for(int i = 0; i < SAMPLES; i++){ 84 vReal[i] = analogRead(audioIn); 85 Serial.println(vReal[i]); 86 vImag[i] = 0; 87 } 88 89 //FFT computation 90 FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); 91 FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD); 92 FFT.ComplexToMagnitude(vReal, vImag, SAMPLES); 93 94 //re-arrange FFT result to match with number of LEDs in strip 95 int step = (SAMPLES/2)/bands; 96 for(int i=0; i<(SAMPLES/2); i+=step) 97 { 98 vReal[i] = constrain(vReal[i],0,2047); //set max value for vReal 99 vReal[i] = map(vReal[i], 0, 2047, 0, valMax); //map vReal values to brightness value range 100 } 101 102 //send to LED strip according to desired values 103 for(int i=0; i<leds; i++) 104 { 105 val=vReal[i+3]; //ignore the bottom 3 freq. bands 0, 1 and 2 (they're always on) 106 //Therefore, 29 LEDs will be addressed. This is why leds is set to 29, not 32. 107 rgbColour = strip.ColorHSV(hueSig[i],sat,val); //calculate colour setting from HSV values 108 strip.setPixelColor(i,rgbColour); //output RGB colour setting to LED 109 strip.show(); //show the colour 110 } 111 112 //if mode switch is moved to Colour Set mode, reset Nano to re-initialize colour parameters 113 if (digitalRead(modeSwitchPin)==LOW){ 114 resetFunc(); 115 } 116} 117
Arduino Sketch
arduino
1#include "Adafruit_NeoPixel.h" 2#include <arduinoFFT.h> 3 4//LED 5 STRIP VARIABLES 6int leds=29; //number of LEDs in strip 7int brightness=64; 8 //overall brightness level of entire strip, 0 (off) to 255 9int sat=255; //saturation 10 from 0(grayscale) to 255(max sat.) 11int val=64; //value (individual brightness) 12 from 0(off) to 255(max) 13int valMax=255; //max value of individual led brightness 14uint32_t 15 rgbColour; //used to convert HSV colour to RGB colour 16long hueBottom; //hue value 17 for top LED, selected with pot at hueBottomPin 18long hueBottomMapped; //mapped 19 to hueMin, hueMax range 20long hueTop; //hue value for bottom LED, selected with 21 pot at hueBottomPin 22long hueTopMapped; //mapped to hueMin, hueMax range 23long 24 hueStep; //hue range (mapped) per led 25long hue=43691; //calculated final hue 26 value, from 65536(violet) to 0(red) 27float k; //steepness of s-curve, read from 28 k Pot as 0-1023 29long hueSig[29]; //array to store hue (with s-curve applied) 30 for each LED 31long hueMin=0; //min possible hue: red 32long hueMax=65536; //max 33 possible hue: violet 34int ledPin=3; //digital output pin to LED strip 35int modeSwitchPin=2; 36 //digital input pin for FFT/Colour Set switch 37int audioPin=A0; //audio input 38 pin 39int satPin=A2; //saturation potentiometer pin 40int brightnessPin=A1; //overall 41 brightness potentiometer pin 42int hueTopPin=A3; //top hue potentiometer pin 43int 44 hueBottomPin=A4; //bottom hue potentiometer pin 45int kPin=A5; //s-curve steepness 46 (k) potentiometer pin 47 48Adafruit_NeoPixel strip = Adafruit_NeoPixel(leds, ledPin, 49 NEO_GRB + NEO_KHZ800); 50 51//FFT VARIABLES 52const int bands=32; //total number 53 of frequency bands, must be <= SAMPLES/2 54const int SAMPLES=64; //2x the number 55 of freq bands. Must be a power of 2 56const int audioIn=A0; //audio input is analog 57 pin A0 58double vReal[SAMPLES]; 59double vImag[SAMPLES]; 60arduinoFFT FFT = arduinoFFT(); 61 //creates an FFT object 62 63//This function causes the Nano to reset. It is necessary 64 to initiate the Colour Set mode. 65void(* resetFunc) (void) = 0; 66 67void setup() 68 { 69 pinMode(modeSwitchPin,INPUT); //set modeSwitchPin as input 70 delay(3000); 71 //power-up safety delay 72 strip.begin(); //initialize LED strip 73 strip.show(); 74 //initialize all pixels 75} 76 77void loop() { 78 79 //While mode switch 80 is low, set colours. Otherwise, perform FFT. 81 while (digitalRead(modeSwitchPin)==LOW){ 82 83 84 //analogRead gives 0-1023 & brightness requires 1-255, so divide reading 85 by 4 86 brightness=analogRead(brightnessPin)/4; //read brightness pot 87 strip.setBrightness(brightness); 88 // set overall brightness 89 //analogRead gives 0-1023 & sat requires 1-255, 90 so divide reading by 4 91 sat=analogRead(satPin)/4; //read brightness pot 92 93 //read hueTop & hueBottom pots. analogRead gives 0-1023 94 hueBottom=analogRead(hueBottomPin); 95 //read hueBottom pot, 0-1023 96 hueBottomMapped=map(hueBottom,0,1023,hueMin,hueMax); 97 98 hueTop=analogRead(hueTopPin); //read hueTop pot, 0-1023 99 hueTopMapped=map(hueTop,0,1023,hueMin,hueMax); 100 101 hueStep=(hueTopMapped-hueBottomMapped)/leds; 102 k=analogRead(kPin); //read 103 k pot, 0-1023 104 105 for (int i=0;i<leds;i++) { 106 hue = hueBottomMapped+(i*hueStep); 107 //calculate hue for each of the LEDs 108 Serial.print ("hue: "); 109 Serial.print 110 (hue); 111 hueSig[i] = hueMax/(1+(pow(2.718,(0-(k/4000000))*(hue-(hueMax/2))))); 112 //apply s-curve 113 Serial.print ("hueSig: "); 114 Serial.println (hueSig[i]); 115 116 rgbColour = strip.ColorHSV(hueSig[i],sat,val); //calculate colour setting 117 from HSV values 118 strip.setPixelColor(i,rgbColour); //output RGB colour setting 119 to LED 120 strip.show(); //show the colour 121 delay(10); 122 } 123 124 } 125 126 //FFT sampling 127 for(int i = 0; i < SAMPLES; i++){ 128 vReal[i] 129 = analogRead(audioIn); 130 Serial.println(vReal[i]); 131 vImag[i] = 0; 132 133 } 134 135 //FFT computation 136 FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, 137 FFT_FORWARD); 138 FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD); 139 FFT.ComplexToMagnitude(vReal, 140 vImag, SAMPLES); 141 142 //re-arrange FFT result to match with number of LEDs 143 in strip 144 int step = (SAMPLES/2)/bands; 145 for(int i=0; i<(SAMPLES/2); 146 i+=step) 147 { 148 vReal[i] = constrain(vReal[i],0,2047); //set max value 149 for vReal 150 vReal[i] = map(vReal[i], 0, 2047, 0, valMax); //map vReal values 151 to brightness value range 152 } 153 154 //send to LED strip according to desired 155 values 156 for(int i=0; i<leds; i++) 157 { 158 val=vReal[i+3]; //ignore 159 the bottom 3 freq. bands 0, 1 and 2 (they're always on) 160 //Therefore, 29 161 LEDs will be addressed. This is why leds is set to 29, not 32. 162 rgbColour 163 = strip.ColorHSV(hueSig[i],sat,val); //calculate colour setting from HSV values 164 165 strip.setPixelColor(i,rgbColour); //output RGB colour setting to LED 166 strip.show(); 167 //show the colour 168 } 169 170 //if mode switch is moved to Colour Set mode, 171 reset Nano to re-initialize colour parameters 172 if (digitalRead(modeSwitchPin)==LOW){ 173 174 resetFunc(); 175 } 176} 177
Downloadable files
Circuit Diagram
Circuit Diagram
Pre-perforated Board Diagram
Pre-perforated Board Diagram
Breadboard Layout
Breadboard Layout
Pre-perforated Board Diagram
Pre-perforated Board Diagram
Breadboard Layout
Breadboard Layout
Circuit Diagram
Circuit Diagram
Documentation
Enclosure Layout - PDF file
Enclosure Layout - PDF file
Enclosure Layout - Open Office Draw file
Enclosure Layout - Open Office Draw file
Enclosure Layout - PDF file
Enclosure Layout - PDF file
Enclosure Layout - Open Office Draw file
Enclosure Layout - Open Office Draw file
Comments