diff --git a/README.md b/README.md index 853363a..060374f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # Arduino Neopixel Using an Arduino with a Neopixel RGB LED strip(60) to create patterns. +Utilizes MSGEQ7 Graphic Equalizer Display Filter to seperate sound into 7 frequency ranges. ## Getting started Download latest Arduino environment(Link in Software) Connect Neopixel strip to 5v source(~3-4 Amp powersupply needed) Connect signal cable from strip to Arduino along with ground cable. +Use proper schematics to wire Audio to MSGEQ7 to output to Arduino. Push script to Arduino board. ### Software diff --git a/Scripts/NeoPixel.ino b/Scripts/NeoPixel.ino index 9e97b33..e2848ff 100644 --- a/Scripts/NeoPixel.ino +++ b/Scripts/NeoPixel.ino @@ -1,15 +1,144 @@ //Neopixel main script #include -#define PIN 6 +#define PIN 6 //strip pin +int analogPin=0; //A0 pin for reading frequency +int strobePin=2; //Ask MSGEQ7 for data +int resetPin=3; //End communication with MSGEQ7 +int spectrumValue[7]; //Array for frequencies +int filter=80; +int highest; +int rotation=0; +int rotationdelay=0; + +int pattern = 0; + Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); void setup() { + Serial.begin(9600); //Debugging serial port + /** + pinMode setup for MSGEQ7 + **/ + pinMode(analogPin, INPUT); + pinMode(strobePin, OUTPUT); + pinMode(resetPin, OUTPUT); + + digitalWrite(resetPin, LOW); + digitalWrite(strobePin, HIGH); strip.begin(); strip.show(); } void loop() { + switch(pattern){ + case 0: + colorLoopProgression(); + break; + case 1: + //placeholder + break; + } +} + + void colorLoopProgression(){ + digitalWrite(resetPin, HIGH); + digitalWrite(resetPin, LOW); + for (int i=0;i<7;i++){ + digitalWrite(strobePin, LOW); + delay(10); + spectrumValue[i]=analogRead(analogPin); + spectrumValue[i]=constrain(spectrumValue[i], filter, 1023); + spectrumValue[i]=map(spectrumValue[i], filter,1023,0,255); + Serial.print(spectrumValue[i]); + Serial.print(" "); + digitalWrite(strobePin, HIGH); + } + Serial.println(); + + highest =0; + for(int i=0; i<7; i++){ + if(spectrumValue[i]>spectrumValue[highest]){ + highest = i; + } + } + Serial.println(highest); + for(int i=30; i<60; i++){ + if(i<30+(spectrumValue[highest]/9)){ + int highestt=0; + if(highestt==0){ + strip.setPixelColor(i, Wheel(rotation+(spectrumValue[highest]/6)+(highest*8))); + } + else if(highest==1){ + strip.setPixelColor(i, strip.Color(spectrumValue[highest], (255-spectrumValue[highest])/2, 0)); + } + else if(highest==2){ + strip.setPixelColor(i, strip.Color(255-spectrumValue[highest], spectrumValue[highest], 0)); + } + else if(highest==3){ + strip.setPixelColor(i, strip.Color(0, spectrumValue[highest], 0)); + } + else if(highest==4){ + strip.setPixelColor(i, strip.Color(0, 0, spectrumValue[highest])); + } + else if(highest==5){ + strip.setPixelColor(i, strip.Color(75, 0, 130)); + } + else if(highest==6){ + strip.setPixelColor(i, strip.Color(100,100,100)); + } + } + else{ + strip.setPixelColor(i, strip.Color(0,0,0)); + } + } + for(int i=30; i>0; i--){ + if(i>30-(spectrumValue[highest]/9)){ + int highestt=0; + if(highestt==0){ + strip.setPixelColor(i, Wheel(rotation+(spectrumValue[highest]/6)+(highest*8))); + } + else if(highest==1){ + strip.setPixelColor(i, strip.Color(255, 127, 0)); + } + else if(highest==2){ + strip.setPixelColor(i, strip.Color(255, 255, 0)); + } + else if(highest==3){ + strip.setPixelColor(i, strip.Color(0, 255, 0)); + } + else if(highest==4){ + strip.setPixelColor(i, strip.Color(0, 0, 255)); + } + else if(highest==5){ + strip.setPixelColor(i, strip.Color(75, 0, 130)); + } + else if(highest==6){ + strip.setPixelColor(i, strip.Color(100,100,100)); + } + } + else{ + strip.setPixelColor(i, strip.Color(0,0,0)); + } + } + if(rotationdelay>=1){ + rotation++; + rotationdelay=0; + } + rotationdelay++; + strip.show(); + } + uint32_t Wheel(byte WheelPos) { + WheelPos = 255 - WheelPos; + if(WheelPos < 85) { + return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); + } + if(WheelPos < 170) { + WheelPos -= 85; + return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); + } + WheelPos -= 170; + return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); }