Components and supplies
Arduino Nano Every
Buck Converter 9vdc to 5vdc
Potentiometer 10k ohm
Audio Cable
Audio Connector, 3.5mm stereo, panel mount
Aluminum Bar, 1/2"x1/8", cut length to fit LED strip
Pre-perforated Prototype Board, 3cm x 7cm min.
Resistor 100k ohm
Barrel Connector for Wall Adapter
Addressable RGB LED Strip, 29 LEDs are needed for this project
Neoprene Tubing, 12mm internal diameter, cut length to fit LED strip
Switch SPST or SPDT
Audio Y Adapter
Resistor 4.7k ohm
Resistor 10k ohm
JST Connectors and Crimper (optional)
Junction Box, 158 x 90 x 60 mm
Capacitor 100 nF
Wall Adapter 9vdc
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 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
Downloadable files
Breadboard Layout
Breadboard Layout
Pre-perforated Board Diagram
Pre-perforated Board Diagram
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
Only logged in users can leave comments
marcaubin
0 Followers
•0 Projects
Table of contents
Intro
5
0