I have changed up Joe's LED table code for my simple 9 RGB LED common Cathode VU meter. It works... But I have no idea how the heck to update my ledArray[] of the RGB grey-scale values so that his code will change my colors.
Ultimately I will use the arduino analog input to control it, but I can't even figure out how to knight rider this code... WHAT THE HECK IS XLAT DOING?? (I added a bunch of info below code to answer questions about circuit)
const int ledCount= 9; // number LED's - i have a column of 9 RGB LEDS
const byte RedPin = 5; // digital pin to control red color
const byte GreenPin =6; // digital pin to control green color
const byte BluePin = 7; // digital pin to control blue color
const analogInputPin = 1; //analog input from low pass filter 0-5volts of music bass
byte Current_Color = 'R';
int power = 16; // allow changing the greyscale power
struct led{ //this makes the ledArray pretty
byte red;
byte green;
byte blue;
};
// structured array to hold the led colors
led ledArray[ledCount] = { {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} }
#include "Tlc5940.h"
void setup()
{
// Setup pins
pinMode(RedPin,OUTPUT);digitalWrite(RedPin,HIGH); //HIGH is off, using a PNP transistor
pinMode(GreenPin,OUTPUT);digitalWrite(GreenPin,HIGH); //samesies
pinMode(BluePin,OUTPUT);digitalWrite(BluePin,HIGH); //samesies
// setup tlc5940
Tlc.init(0);
startXLATCallback(); //WHAT IS THIS???
Tlc.update();
}
void loop()
{
}
// do something every 2 periods, so ~2048us
// TLC5940 multiplexing code
#define XLAT_PERIODS 2
volatile uint8_t timesCalled;
volatile void myXLATCallback()
{
if (timesCalled != 0) timesCalled--;
else
{
timesCalled = XLAT_PERIODS;
Send_data();
Tlc.update();
}
set_XLAT_interrupt(); // so this will continue to be called
}
void startXLATCallback() {
timesCalled = XLAT_PERIODS - 1;
tlc_onUpdateFinished = myXLATCallback;
myXLATCallback();
}
// update the tlc5940 chip
void Send_data()
{
if(Current_Color == 'R')
{
for(int i=0; i < ledCount ; i++)
{
Tlc.set(i+1, ledArray[i].red*power); //my leds are attached to pin 1-9 on tlc
}
Turn_off();
Tlc.update();
while(tlc_needXLAT); //WHAT THE HECK??? whyy
Turn_on();
Current_Color = 'G';
}
else if(Current_Color =='G')
{
for(int i=0; i <ledCount ; i++)
{
Tlc.set(i+1, ledArray[i].green*power);
}
Turn_off();
Tlc.update();
while(tlc_needXLAT); //what is this?
Turn_on();
Current_Color = 'B';
}
else
{
for(int i=0; i < ledCount ; i++)
{
Tlc.set(i+1, ledArray[i].blue*power);
}
Turn_off();
Tlc.update();
while(tlc_needXLAT); //MEOWWW
Turn_on();
Current_Color = 'R';
}
}
// turn on or off the respective anode transistor
void Turn_off()
{
digitalWrite(RedPin,HIGH);
digitalWrite(GreenPin,HIGH);
digitalWrite(BluePin,HIGH);
delayMicroseconds(10);
}
void Turn_on()
{
switch(Current_Color){ //switch the transistors sexy volt
case 'R':
delayMicroseconds(10);
digitalWrite(RedPin, LOW);
digitalWrite(GreenPin, HIGH);
digitalWrite(BluePin, HIGH);
break;
case 'G':
delayMicroseconds(10);
digitalWrite(RedPin, HIGH);
digitalWrite(GreenPin, LOW);
digitalWrite(BluePin, HIGH);
break;
case 'B':
delayMicroseconds(10);
digitalWrite(RedPin, HIGH);
digitalWrite(GreenPin, HIGH);
digitalWrite(BluePin, LOW);
break;
}
}
EXTRA INFO
I use arduino outputs to switch PNP transistor base to ground and send my high current supply (800mA @ 5.5 V) to the 9 LED anodes. 3 transistors are used, one for each color (R G B). So at any time, only one transistor/color is engaged...
My LEDs are in a column of 9. pin 1 on tlc5490 relates to LED 1 at the bottom of my column...etc pin 9 is LED 9 at top of my column.
I limited current to 25mA per LED.