Circuit is 9 RGB LED's (see below). This is the start of my code, and I wanted to make sure this is an acceptable method to multiplex. I, also, would love advice on how to add the VU meter effect ( fade between changes). You don't have to write the code, just give me some tips on how to incorporate the VU effect.
I will be adding 2 analog reads that are measuring music volume at 2 frequencies
(music -> LPF/HPF-> op amp -> envelop detector)
I think my biggest problem will be finding a running min/max from the analog read so my VU meter will utilize all LEDs?
int redPin = 8; //pwm analog out for all red LEDs
int bluePin = 9; //pwm analog out for all blue LEDs
int greenPin = 10; //pwm analog out for all green LEDs
int ledCount = 9; //# of RGB commone cathode LEDs
int groundPin[ledCount] = {0,1,2,3,4,5,6,7,8}; //digital grounds
struct RGB {
byte r;
byte g;
byte b;
};
RGB ledArray[] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
//sets all LED colors
updateLedArray(255, 255, 255, ledCount, "all"); //sets all 9 LEDs to full color to start
//declare grounds and debug all LEDs
for(int i=0; i<ledCount; i++)
{
pinMode(groundPin[i],OUTPUT); //cycle each ground pin mode
digitalWrite(groundPin[i],LOW);
}
}
void loop()
{
updateLedArray(255, 0, 150, 9, "all");
//multiplex the ledArray values through each LED
for(int i=0; i<ledCount; i++){
if(ledArray[i].r>10 || ledArray[i].g>10 || ledArray[i].b>10){
//ground LED if it has pwm going to it
analogWrite(redPin, ledArray[i].r);
analogWrite(greenPin, ledArray[i].g);
analogWrite(bluePin, ledArray[i].b);
digitalWrite(groundPin[i], LOW);
delay(1);
digitalWrite(groundPin[i], HIGH);
}
}
}
//the function that changes the LED array depending on the methd that you want
void updateLedArray(byte sred, byte sgreen , byte sblue, byte ledn, char methd)
{
if(methd == "all"){ //Change all colors in ledArray
for(int i=0 ; i<= ledCount ; i++)
{
ledArray[i].r = sred;
ledArray[i].g = sgreen;
ledArray[i].b = sblue;
}
}
}