The title pretty much sums up all that I'm trying to accomplish. I am currently trying to to take 3 incoming RGB values, say the color orange, where R = 255, G = 165, B = 0, to a uint32_t HEX color code, ie. 0xFFA500. I understand the first two bytes correspond to red, the second green, so forth. I do not now what code to right to convert the 3 integers to bytes, then string all three and the leading 0x together.
No I have not written any code yet. I have tried but can not materialize my thoughts, as this is uncharted territory for me. I have read about how you can divide by 16 and then multiple the remainder ma thematic solution, still don't know how to combine the bytes. The union idea is way over my head, larryd, do you have another way, or explain how that code you provided works? would be sooo appreciated. Best.
unsigned long myVariable;
. . .
Serial.print(“0x”); //prints 0x
Serial.println(assembledColour.RGB, HEX); //this will print FFA500 therefore you get 0xFFA500
myVariable = assembledColour.RGB; //saves the assembled RGB value in variable myVariable
That code works! You are one of the few respondents I have come across that doesn't beat around the bush and answers the question succinctly. Thank you much.