Created
September 6, 2012 02:14
-
-
Save lrvick/3649982 to your computer and use it in GitHub Desktop.
Arduino sketch to convert output from a MSGEQ7 graphic equalizer display filter to RGB values that are fed to BlinkM tricolor LED modules for music visualization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Wire.h" | |
#include "BlinkM_funcs.h" | |
#define blinkm_addr 0x00 | |
#define blinkm1_addr 0x09 | |
#define blinkm2_addr 0x10 | |
int spectrumReset=5; | |
int spectrumStrobe=4; | |
int spectrumAnalog=0; //0 for left channel, 1 for right. | |
int Spectrum[7]; // Spectrum analyzer read values will be kept here. | |
void setup() { | |
BlinkM_beginWithPower(); | |
BlinkM_stopScript(blinkm_addr); | |
BlinkM_setFadeSpeed(blinkm_addr, 45); | |
pinMode(spectrumReset, OUTPUT); | |
pinMode(spectrumStrobe, OUTPUT); | |
//Init spectrum analyzer | |
digitalWrite(spectrumStrobe, LOW ); delay(1); | |
digitalWrite(spectrumReset, HIGH ); delay(1); | |
digitalWrite(spectrumStrobe, HIGH ); delay(1); | |
digitalWrite(spectrumStrobe, LOW ); delay(1); | |
digitalWrite(spectrumReset, LOW ); delay(5); | |
Serial.begin(9600); | |
} | |
void loop() { | |
byte Band,MaxLevel; | |
static unsigned int Divisor = 80, ChangeTimer=0; | |
MaxLevel = 0; | |
for( Band=0; Band <7; Band++ ){ | |
Spectrum[Band] = ( | |
(analogRead(spectrumAnalog) + analogRead(spectrumAnalog) | |
) >>1 ) / Divisor; | |
digitalWrite(spectrumStrobe,HIGH); | |
digitalWrite(spectrumStrobe,LOW); | |
Serial.print(Band); Serial.print("\t"); | |
Serial.print(Spectrum[Band] * 51,DEC); Serial.println("\n"); | |
if(Spectrum[Band] > MaxLevel){ | |
MaxLevel = Spectrum[Band]; | |
} | |
if (MaxLevel >= 5) { | |
Divisor=Divisor+1; | |
ChangeTimer = 0; | |
} else if( MaxLevel < 4 && Divisor > 65 ){ | |
if (ChangeTimer++ > 20) { | |
Divisor--; | |
ChangeTimer = 0; | |
} | |
} else { | |
ChangeTimer = 0; | |
} | |
} | |
unsigned int r1 = Spectrum[0] * 51; | |
unsigned int g1 = Spectrum[1] * 51; | |
unsigned int b1 = Spectrum[2] * 51; | |
unsigned int r2 = Spectrum[3] * 51; | |
unsigned int g2 = Spectrum[4] * 51; | |
unsigned int b2 = Spectrum[5] * 51; | |
unsigned int brightness = Spectrum[6] * 51; | |
BlinkM_fadeToRGB(blinkm1_addr,r1,g1,b1); | |
BlinkM_fadeToRGB(blinkm2_addr,r2,g2,b2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment