Show Posts
|
|
Pages: 1 [2]
|
|
17
|
Using Arduino / Programming Questions / tlc5940 multiplexing code assistance
|
on: August 19, 2011, 10:02:35 am
|
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.
|
|
|
|
|
18
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 17, 2011, 07:08:21 am
|
|
I couldn't fix the dimming issue, which I figure was an inherent problem with multiplexing 9 LEDs on/off.
For all that read this later, I am now using a tlc5490 which allows PWM with up to 16 LEDs. I multiplex through each color (RGB), but all LED's are grounded all the time. This is much brighter and easier.
|
|
|
|
|
20
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 15, 2011, 12:08:14 pm
|
|
Ignore 40 Hz freq. This is just part of the program I was using. SEE NEW PIC
I am onto something... I think that the 1ms pulse of 255 PWM is the problem. I believe a piranha rgb can take 100ma if it is pulsed. Anddddd the arduino only puts out 40mA?? Transistor?
ORRR PWM only works with a duty cycle of ~450Hz. Soooo. If I pulse at 1ms i am cutting the PWM signal in half... Shucks
Sex
|
|
|
|
|
21
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 15, 2011, 10:42:22 am
|
1st off - thanks for all your help. I can't tell you how demoralized I am with this problem... Here is a dumbed down version of how I am multiplexing... I don't understand what you are taking about when you bring up the 40 Hz or 490Hz? So, PWM at "255" will pulse 5V at a freq of 490 Hz? 5V every ~2ms (490Hz) doesn't seem right? 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[] = {{255,0,0},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{255,0,0}};
void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT);
//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() {
//multiplex the ledArray values through each LED for(int i=0; i<ledCount; i++){
if(ledArray[i].r>0 || ledArray[i].g>0 || ledArray[i].b>0){ //ground LED if it has pwm going to it analogWrite(redPin, ledArray[i].r); //red pin pwm set for specific LED color analogWrite(greenPin, ledArray[i].g); analogWrite(bluePin, ledArray[i].b); digitalWrite(groundPin[i], LOW); //ground the corresponding LED ground so it lights up delay(1); //multiplex delay that bitch digitalWrite(groundPin[i], HIGH); //un-ground the LED and go to the next one up } } }
|
|
|
|
|
22
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 15, 2011, 08:07:34 am
|
Do you have a resistors on pin 9-11? nope. nothing changes much when I put a small resistor. ( less than 100 ohm) And you have to select only one pin 0-8 at a time, I'm not sure what do you mean 1 or 2 ms?
1 or 2 ms is the time I leave each LED on before switching. So R G and B will be lit for 1ms before switching to the next LED. only one pin (0-8 Digital out) are LOW at any time. They are usually OFF, or digital HIGH; since i'm using my digital pins to ground the beast.
|
|
|
|
|
23
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 14, 2011, 09:58:33 pm
|
|
If I Multiplex through all 9 LED's, they are dim with a 1ms or 2ms delay
GRRRRRRR
Is it because 1ms is too fast for pwm to brighten 1 LED? If i slow it down, they are much brighter. Is is an issue with using the Digital out pin HIGH on the other LED's causing voltage to flow through the cathode of the RGB LED??? Help
|
|
|
|
|
24
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 12, 2011, 10:00:02 am
|
|
Great advice
Well after a night of testing im going to lose my mind! The multiplexing works great, but making a sounds filter without an oscilloscope SUCKS!
I will not use the speaker wire as input, and I will use an electret... Let see if i can figure that out this weekend
|
|
|
|
|
25
|
Using Arduino / LEDs and Multiplexing / Re: Simple VU meter multiplex issue
|
on: August 11, 2011, 03:43:07 pm
|
Min/Max I will have to establish a running min/max that will effectively adjust my range in order to ensure that all LEDs will be used... we will see how easy that is... (I am using a speaker output from a stereo for my audio input... sooo range tends to change{I use variable gain / potentiometer for this}) methd == "all", if methd is char, you can't compare it to a string "all". Damn... any alternative for using logic on characters? can you put more details how 2 measurements LPF/HPF would affect color of lighting? Analog input from LPF/HPF & peak detector will be used in selectable methods. for example: - LP signal (0-1024) peak detector signal will be used to change the level of the VU meter (Which LED is lit)
- HP signal peak detector signal will be used to change the color of the VU meter
- Visa Versa
|
|
|
|
|
26
|
Using Arduino / LEDs and Multiplexing / Simple VU meter multiplex issue
|
on: August 11, 2011, 12:45:02 pm
|
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; } } }
|
|
|
|
|