Line 99 if this sketch casts an array of bytes to chars and prints them to serial (is this accurate so far?)
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &onoffbutton) {
Serial.print(F("Got: "));
Serial.println((char *)onoffbutton.lastread);
}
}
For my purposes this (char *)onoffbutton.lastread is what I'm interested in and will return a standard hex color code like #FF0000
Assuming the # is byte at index zero how do I extract the red, green, and blue parts of the color code separatly and convert them to the three separate rgb decimals so I can process them?
I can probably hack together the conversion hex to byte conversion, but what I really need help understanding is how to access the color's byte pairs. I'm pretty bad at c and it's been a while.
Assuming everything is correct, you can extract the rgb like so:
~~ ...~~
~~ char *str = (char *)onoffbutton.lastread;~~
~~ byte r = str[1];~~
~~ byte g = str[2];~~
~~ byte b = str[3];~~
So that'll extract each individual byte, right. So given the hex string "#FF7F00" how do I convert the three hex pairs to bytes from 0-255? See my psuedo code below.