Go Down

Topic: Constants question (Read 293 times) previous topic - next topic

roontoon

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);


retrolefty

#1
Dec 12, 2012, 01:09 am Last Edit: Dec 12, 2012, 01:12 am by retrolefty Reason: 1
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: [Select]
const char colorRed[] = {127, 0, 0};
const char colorGrn[] = {0, 127, 0};
const char colorBlu[] =  {0, 0, 127};


Lefty

PaulS

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.

guix

I think you want something like that?

http://codepad.org/veBBXu6k

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy