Pages: [1]   Go Down
Author Topic: TLC 5940 and vars.  (Read 713 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone, I'm new to the arduino world. I have desided to try to build an led matrix useing the TLC5940 led driver. We are working very small scale to start with but heres my issue with useing the tlc5940 lib.
I want to be able to turn on several leds at a time with having to call them one by one in the code. here is what i have so far but it does not work correctly as in the code it turns on led 0 1 2 5 10 15 when all i wanted was to turn on led 0, 5, 10, 15

this code is partial to the whole code i have which just as a bunch of these statements which dont work lol.

EDIT: we are starting off with 1 tlc and 16 single leds, next step will be 3 tlc  and 16 RGB leds

Quote
#include "Tlc5940.h"

void setup() {
  Tlc.init();
}

void setLED(int level, ... )
{
   va_list leds;
   int ledNumber = -1;

   va_start(leds, level);
   while((ledNumber = va_arg(leds, int)) != -1)
   {
      Tlc.set(ledNumber, level);
   }
   va_end(leds);
}

void loop() {
  setLED(4095, 0, 5, 10, 15);
  Tlc.update();
  delay(550);
}


any and all help is appreciated


« Last Edit: January 14, 2011, 01:29:23 pm by sonic2wb » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you successfully used va_list, va_start, va_arg, and va_end on the Arduino?

I modified your code a bit:
Code:
void setLED(int level, ... )
{
  int i = 0;
   va_list leds;
   int ledNumber = -1;

   va_start(leds, level);
   while((ledNumber = va_arg(leds, int)) != -1)
   {
     Serial.print(i++);
     Serial.print(") Led number: ");
     Serial.print(ledNumber);
     Serial.print("; level: ");
     Serial.println(level);
   }
   va_end(leds);
}

void setup()
{
  Serial.begin(19200);
  setLED(4095, 0, 5, 10, 15);
}

void loop()
{
}
I ran this and got
Code:
0) Led number: 0; level: 4095
1) Led number: 5; level: 4095
2) Led number: 10; level: 4095
3) Led number: 15; level: 4095
4) Led number: 6658; level: 4095
5) Led number: 23296; level: 4095
6) Led number: 8233; level: 4095
7) Led number: 25932; level: 4095
8) Led number: 8292; level: 4095
9) Led number: 30062; level: 4095
10) Led number: 25197; level: 4095
11) Led number: 29285; level: 4095
.
.
.
705) Led number: 28471; level: 4095
706) Led number: -12657; level: 4095
707) Led number: 24543; level: 4095
708) Led number: -16524; level: 4095
709) Led number: 28652; level: 4095
710) Led number: 12197; level: 4095
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah i see, i was just reading that the va_ command set doesnt seem to work well with arduino. any other ideas on how to do this.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Default arguments:

Code:
void setLED(int level, int led1 = 0, int led2=0, int led3=0, ..., int led16=0)
{
   if(led1 > 0)
      // do something
   if(led2 > 0)
      // do something
   if(led3 > 0)
      // do something
   if(led4 > 0)
      // do something
.
.
.
   if(led16 > 0)
      // do something
}
In the argument list, you won't actually use ... You will list all 16 values.

Another way would be to pass an array of values, with -1 as the last value. Then, step through the array until you find a -1.
Logged

Pages: [1]   Go Up
Jump to: