Hello,  I am new to coding and i am working on a project using

Hello,
I am new to coding and i am working on a project using APA102 strips and I’m running into an issue when working with Arrays. I have set up a Array with data already initialized into it . I would like to assign the color an LED lights up from the data within the array. When I assign an LED RGB color normally in the loop it provides me with the correct color If you look at the sketch below LED[0] = CRGB(255,255,0) assigns color properly yet the other LED’s attempting to access Array information are all just outputting the wrong color or None at all. Leds[1] = CRGB (TestGrid[1][2]) should be outputting a Green pixel yet when my sketch is running it will output nothing. If I change the value for that row/column in my grid to (255,0,255) Magenta it turns the LED on and only displays a bright blue color. If anyone could take a peak at my sketch and help point me in the right direction to fix this issue it would be greatly appreciated. I have also attempted this with HEX colors instead of RGB values and I get the same results.

http://pastebin.com/fAM09PcH

I recently had something similar happen, but it was due to a faulty solder connection. Oh, and can you confirm that your color order is correct? There is a test sketch in the examples folder of the library.

Yes, I have Used the Test Sketch and like I stated before if you look at LED[0] = (255,255,0) ; this format works I can edit this to change to any color I wish or if use this same method on other rows it works properly. It seems to only be an issue when accessing information within the Array

Unfortunately - you can’t use things quite the way you are with the array. In C, the value of the expression (0,255,0) is just 0 (it’s referred to as the comma operator). CRGB(255,255,255) works because that is creating a CRGB object and passing the three values into its constructor.

So, when you pull a value out of TestGrid, it’s just going to pull a single integer value, the 3rd of each set of (0,255,0), and pass that into the constructor for CRGB, which will be interpreted as, well, something not useful to you.

I would suggest maybe something like:

#define TORGB(R,G,B) (uint32_t)( ((R)<<16) | ((G)<<8) | (B) )

uint32_t TestGrid[5][4] = {
TORGB(0,255,0), TORGB(0,0,255), TORGB(0,255,0), TORGB(0,255,0),
TORGB(0,255,0), TORGB(0,0,255), TORGB(0,255,0), TORGB(0,255,0),
TORGB(0,255,0), TORGB(255,0,255), TORGB(255,0,0), TORGB(0,255,0),
TORGB(0,255,0), TORGB(0,0,255), TORGB(255,0,255), TORGB(0,255,0),
TORGB(0,255,0), TORGB(0,255,0), TORGB(0,255,0), TORGB(0,255,0)
};

and then evertying else will work like you want. The #define TORGB line creates a macro that converts a set of R,G,B values into a single 32-bit integer representation for a color - which then gives you an array of those 32-bit integers, and then when you pull those values out and pass them into the CRGB constructor, they will do what you expect.

Thank you , That definitely Helps. I am curious as to how the Define line works though, What if i wanted to set this up as 6 Digit Hex Colors instead of RGB Values. ?

The you don’t need the macro at all, you can just replace a TORGB(0,255,0) with 0x00FF00

The define line creates a macro (called TORGB) that translates the three r g b values into a single integer value that is the same as your six digit hex values.

That’s sweet. Great info Daniel.

Yes, thanks for the help daniel. This shall help with my project. I will update you guys when I get it going!