Pages: [1]   Go Down
Author Topic: Constants question  (Read 252 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to define each color with its RGB equivalent as a constant. I have tried something like the code below but it returns 0 instead of 127,0,0 as I would like. I would like to do this to make my code more readable. Any guidance? Thanks

const char red= '127,0,0';         //Red

setSpoke(0,strip.Color(red));   //red
Serial.println(red);

Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you should read up on the use of arrays, as that is probably how you could do what you are looking for.


Code:
const char colorRed[] = {127, 0, 0};
const char colorGrn[] = {0, 127, 0};
const char colorBlu[] =  {0, 0, 127};

Lefty
« Last Edit: December 11, 2012, 07:12:12 pm by retrolefty » Logged

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

But, why would you use char variables or arrays to hold numbers? byte or uint8_t seem more logical to me.

Yes, I know it makes no difference to the compiler, as long as you keep in mind the range of values that can be stored in a char (which is not the same range as can be stored in a byte. even though they are the same size).

It makes a difference to humans trying to follow the code, though.
Logged

France
Offline Offline
Edison Member
*
Karma: 37
Posts: 1008
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you want something like that?

http://codepad.org/veBBXu6k
Logged

Pages: [1]   Go Up
Jump to: