Go Down

Topic: RGB leds + Vu meter help (Read 999 times) previous topic - next topic

Interesting

I have a few questions here -> I'm trying to interface an Arduino with a Vu meter to have some RGB Leds flick through at the pace of the music. I'm using 4 vu meter inputs (it's from a shirt, so the circuitry there is complete and works). I'm going to look at 4 of the last vu meter inputs, look at all four vu meter inputs, store them in an array, take the averages, put that an in array, cycle through a for loop that looks at the average, if average >= 0.5, fade up, if it's not, fade down. The trouble I'm facing now is figuring out how to use the other colors... I was thinking of taking a timer, looking at the fade status (it fades up for 0.5 seconds) and if it's no longer fading, and it's current at 4095, then I'll fade up the next color (LED + 1) then do that again for LED + 2.

I'm using a TLC5940, and in my recent testing with it just cycling through the default programs, it doesn't seem to be working properly. The LEDs are erratic and flicker quite heavily (noticeably). It's hooked up correctly - as the lights do work.

Some brief stats-

Arduino Duemilanove
TLC5940
4x RGB Leds
Sound reactive circuitry from electronic shirt.

For the sound reactive circuitry - the recorded voltage is a bit finicky. For some reason there's an inverter on the board that run out to the shirt, and the voltage fluctuates wildly. The chip on the board is a constant current chip, so maybe it throws up 80v to get 15 mA through my volt meter? Anyway, I'm going to use a voltage divider to bring the voltage down to something reasonable, as the Arduino has a 1 meg pull up resistor, the current going through that branch can be considered 0, right?

Here's the untested code that I currently have - I'm a bit stuck as the best route to go about actually running the lights, I'm currently looking at the average of 4 of the past inputs on a Vu input, if the average is > 0.5, it sets the LED to 4095 and starts fading down.



My code is having some trouble with this line ----
Code: [Select]
tlc_addFade(l, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l), 0, startMillis, endMillis);
       
asking for a primary expression before Tlc5940, what's this mean?


Here's the code I'm currently working with...


Code: [Select]
#include "Tlc5940.h"
#include "tlc_fades.h"

int db0[] = {0,0,0,0};
int db1[] = {0,0,0,0};
int db2[] = {0,0,0,0};
int db3[] = {0,0,0,0};

int db0pin = 16;
int db1pin = 17;
int db2pin = 18;
int db3pin = 19;

int db0tot = 0;
int db1tot = 0;
int db2tot = 0;
int db3tot = 0;

int dbavg[] = {0,0,0,0};

int l = 0;
int x = 0;

void setup()
{
 pinMode(db0pin, INPUT);
 pinMode(db1pin, INPUT);
 pinMode(db2pin, INPUT);
 pinMode(db3pin, INPUT);
 Serial.begin(9600);
 Tlc.init();
}

void loop()
{

 for(x = 0; x <= 3; x++)
 {
   db0[x] = analogRead(db0pin);
   db1[x] = analogRead(db1pin);
   db2[x] = analogRead(db2pin);
   db3[x] = analogRead(db3pin);
 }
 
 for(x = 0; x <= 3; x++)
 {
   db0tot += db0[x];    
   db1tot += db1[x];    
   db2tot += db2[x];
   db3tot += db3[x];  
 }
 
 dbavg[0] = db0tot/4;
dbavg[1] = db1tot/4;
dbavg[2] = db2tot/4;
dbavg[3] = db3tot/4;

 for(int t = 0; t <=3; t++) //offsetting for the LED selected
 {
   if(t == 1)
   {
     l = 3;
   }
   if(t == 2)
   {
     l = 6;
   }
   if(t == 3)
   {
     l = 9;
   }
 
   if(dbavg[t] < 0.5)
   {
     if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2)
     {
         uint16_t duration = 200;
         uint32_t startMillis = millis() + 50;
         uint32_t endMillis = startMillis + duration;
     //    tlc_addFade(l, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l), 0, startMillis, endMillis);
     //    tlc_addFade(l+1, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l+1), 0, startMillis, endMillis);
    //     tlc_addFade(l+2, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l+2), 0, startMillis, endMillis);
     }
     tlc_updateFades();
   }
   
   
   else
   {
     if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2)
     {
         uint16_t duration = 150;
         uint32_t startMillis = millis() + 50;
         uint32_t endMillis = startMillis + duration;
         tlc_addFade(l, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l), 4095, startMillis, endMillis);
       
       if(uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l) == 4095)
       {  
         uint16_t duration = 100;
         uint32_t startMillis = millis() + 50;
         uint32_t endMillis = startMillis + duration;
         tlc_addFade(l+1, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l+1), 4095, startMillis, endMillis);
       }
       if(uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l+1) == 4095)
       {
         uint16_t duration = 50;
         uint32_t startMillis = millis() + 50;
         uint32_t endMillis = startMillis + duration;
         tlc_addFade(l+2, uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l+2), 4095, startMillis, endMillis);
        }
      }
            tlc_updateFades();
   }
     
       
   }
 }



Every call to uint16_t Tlc5940::get(TLC_CHANNEL_TYPE l) generates an error.

Thanks!

tl;dr - Interfacing Arduino with Vu meter from shirt, code is acting a little finicky, the TLC5940 flickers with the default programs. Voltage from output of shirt is sporadic. Hmmm... maybe those weren't LEDs on the shirt...

madworm

#1
Dec 29, 2009, 12:51 pm Last Edit: Dec 29, 2009, 12:53 pm by madworm Reason: 1
Try removing the uint16_t before the function.
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

Interesting

#2
Dec 29, 2009, 05:23 pm Last Edit: Dec 29, 2009, 05:32 pm by Interesting Reason: 1
Hmmm tried that, but to no avail.

Realized I didn't have tlc5940.h included  :o but that didn't help putting it in.

Code: [Select]

   x = Tlc5940::get(TLC_CHANNEL_TYPE 3);

That spits out the error: expected primary-expression before numeric constant.

Code: [Select]

   x = Tlc5940::get(3);

That guy says 'Cannot call member function 'uint16_t Tlc5940::get(uint8_t)' without object'.

EDIT:
Fixed that one - Had to declare Tlc5940 Tl; at the beginning, then change the function calls to Tl.get(channel);

PaulS

The get function is not a static member. It can not be called that way.

You need to create an object of that class, and call the object's methods:

Code: [Select]
Tlc5940 myWhatever;

void loop()
{
// use the Tlc5940 object
  uint16_t someVal = myWhatever.get(3);
}


I'd recommend that you take at least a cursory look at a C++ book, to get some understanding of object-oriented design, and how to use classes. Reading a C book and understanding that programming is not cutting and pasting wouldn't hurt, either.

Go Up