How to assign predefined array of RGB values to setLED?

Use "whichColor" as simply an index into "someColors". (see comment in reply #16)

Hi AWOL,

tlc.setLED(randno, r, g, b);

I tried that earlier (and again) and I get the compile error: " 'r' was not declared in this scope"

mbiasotti: I tried that earlier (and again) and I get the compile error: " 'r' was not declared in this scope"

No, but "someColors[whichColor].r" is.

Hi AWOL,

Do you mean like this?

tlc.setLED(whichChannel, someColors(whichColor));

or

tlc.setLED(whichChannel , someColors[whichColor].r , someColors[whichColor].g , someColors[whichColor].b );

Which one did the compiler like best?

Hi AWOL,

The second one does compile and upload. The first one does not and give warning ('someColors' cannot be used as a function'. )

...but running my circuit now and is not doing what I thought it would - all leds randomly light after a minute or so but they are all white (1,1,1) and all stay lit hum?

So I input some code to have my Serial monitor show me what's being passed:

Serial.print(whichChannel);
Serial.print ("    ");
Serial.print (someColors[whichColor].r);
Serial.print (",");
Serial.print (someColors[whichColor].g);
Serial.print (",");
Serial.println (someColors[whichColor].b);

and what I'm getting on my serial monitor is this: (first number is the led # and then followed by the predefined rgb value:

1 183,1,255 2 255,1,159 11 1,1,16 11 255,1,153 6 255,255,1 4 1,97,255 9 1,255,41 5 255,255,1 1 255,1,229 10 255,1,255 3 1,255,255 3 255,255,1 2 1,97,255 9 1,97,255 13 255,1,159 4 183,1,255

So somehow the r.g.b values are being truncated to a max of 255 (instead of 4095)?

Also getting this warning after compiling (truncated out the path of my .ino with ...)

...wave-light-version1.ino:55:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]

...wave-light-version1.ino:55:1: warning: narrowing conversion of '4095' from 'int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]

...wave-light-version1.ino:55:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]

...wave-light-version1.ino:55:1: warning: narrowing conversion of '2601' from 'int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]

...wave-light-version1\wave-light-version1.ino:55:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]

AWOL,

I think I know why? do I need to use "uint16_t" to declare them as 16 bit?

like this:

tlc.setLED(whichChannel , uint16_t (someColors[whichColor].r) , uint16_t (someColors[whichColor].g) , uint16_t (someColors[whichColor].b) );
struct rgbcolor {
  byte r;    // red value 0 to 4095

Truncated? The comment is simply wishful thinking.

AWOL,

so, maybe I need to use "uint16_t" to declare them as 16 bit values so I tried this:

tlc.setLED(whichChannel , uint16_t (someColors[whichColor].r) , uint16_t (someColors[whichColor].g) , uint16_t (someColors[whichColor].b) );

that does compile but still getting max values of 255 on my serial monitor?

Casting an eight bit value to a sixteen bit datatype does not (cannot) increase its range.
Try starting with a sixteen bit value.

Hi AWOL,

"Try starting with a sixteen bit value"

Where do I assign that? Can you show me?

struct rgbcolor {
  byte r;    // red value 0 to 4095
  byte g;   // green value
  byte b;   // blue value

I thought I already had shown you, but there I've shown it again. And again, a comment don't make it so.

AWOL,

I already have my struct assign in that way in my code and it is truncating value higher than 255 (like 4095) - see my post #25.

Mark

Hi,

You appear to be missing the obvious:

You appear to be missing the obvious
struct rgbcolor {
  byte r;    // red value 0 to 4095       <<<<< byte max == 255; int max == 32,767
  byte g;   // green value
  byte b;   // blue value

best,
Michael

Thank you Michael (and AWOL) for your patience - learning...

Mark