Hi all,
I’m on with creating a simple project using a 1m strip of neopixels and a spectrum shield from sparkfun. At the moment i have the neopixel strip connected to the arduino and i have uploaded the Cylon Eye v1.10 script created by EternalCore to the board so that a single led chases back and forth.
I’ve also connected the spectrum shield to the arduino and played around with some example code to see it in action.
What I’d’ like my set-up to do is when the single led chases back and forth, it also changes colour to the music.
how would i go about making this happen. Ive included to two scripts that I’ve been playing with. is there any way i could combine the two together to get what i need.
or is there another way i could approach this task.
any help would be really grateful.
Chaser Code
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define TPIXEL 144
int wait_T=40;
int refresh=1330;
int PixelCount=144;
int Pixel_Start_End=0;
boolean UsingBar = false;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(TPIXEL, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
CylonEyeUp(strip.Color(255,255,255), strip.Color(0,0,0), strip.Color(0,0,0), wait_T, PixelCount, Pixel_Start_End);
CylonEyeClear(wait_T, PixelCount, Pixel_Start_End);
}
void CylonEyeClear(uint8_t Delay, int TotalPixels, int pStart) {
for(int i=pStart; i<TotalPixels+2; i++) {
strip.setPixelColor(i, strip.Color(0,0,0));
strip.show();
}
}
void CylonEyeUp(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pStart) {
for(int i=pStart; i<TotalPixels; i++) {
if(!UsingBar) { strip.setPixelColor(i+2, Ctt); }
strip.setPixelColor(i+1, Ct);
strip.setPixelColor(i, Co);
strip.setPixelColor(i-1, Ct);
if(!UsingBar) { strip.setPixelColor(i-2, Ctt); }
if(!UsingBar) {
strip.setPixelColor(i-3, strip.Color(0,0,0));
} else {
strip.setPixelColor(i-2, strip.Color(0,0,0));
}
strip.show();
delay(Delay);
}
}
Spectrum Code
#include <Adafruit_NeoPixel.h>
#define PIN_NEOPIXELS 6
#define PIN_STROBE 4
#define PIN_RESET 5
#define PIN_LEFT 0 //analog
#define PIN_RIGHT 1 //analog
#define NUMLEDSPERSEGMENT 144
#define NUMLEDS NUMLEDSPERSEGMENT * 1
#define MINPOWER 128
#define MAXPOWER 1023
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN_NEOPIXELS, NEO_GRB + NEO_KHZ800);
//band arrays
int left[7];
int right[7];
void setup() {
//initialize neopixels
strip.begin();
strip.setBrightness(32); //otherwise I'll become blind during testing ... ;)
strip.show();
//initialize eq
pinMode(PIN_RESET, OUTPUT); // reset
pinMode(PIN_STROBE, OUTPUT); // strobe
digitalWrite(PIN_RESET,LOW); // reset low
digitalWrite(PIN_STROBE,HIGH); //pin 5 is RESET on the shield
}
void loop() {
readMSGEQ7();
int rLeft = colorValue((left[0]+left[1])/2);
int gLeft = colorValue((left[2]/2+left[3]+left[4]/2)/2);
int bLeft = colorValue((left[5]+left[6])/2);
int rRight = colorValue((right[0]+right[1])/2);
int gRight = colorValue((right[2]/2+right[3]+right[4]/2)/2);
int bRight = colorValue((right[5]+right[6])/2);
for (int i = 0; i < NUMLEDSPERSEGMENT; i++) {
strip.setPixelColor(i, (i<=rLeft) ? 255 : 0,(i<=gLeft) ? 255 : 0,(i<=bLeft) ? 255 : 0);
strip.setPixelColor(i + NUMLEDSPERSEGMENT, (i<=rRight) ? 255 : 0,(i<=gRight) ? 255 : 0,(i<=bRight) ? 255 : 0);
}
strip.show();
delay(40);
}
int colorValue(int powerValue)
{
return map(powerValue, MINPOWER, MAXPOWER, 0, NUMLEDSPERSEGMENT);
}
void readMSGEQ7()
{
//reset the data
digitalWrite(PIN_RESET, HIGH);
digitalWrite(PIN_RESET, LOW);
//loop thru all 7 bands
for(int band=0; band < 7; band++) {
digitalWrite(PIN_STROBE,LOW); // go to the next band
delayMicroseconds(50); //gather some data
left[band] = analogRead(PIN_LEFT); // store left band reading
right[band] = analogRead(PIN_RIGHT); // store right band reading
digitalWrite(PIN_STROBE,HIGH); // reset the strobe pin
}
}