I am trying to send a lot of serial commands really fast. I basically need to change color of my LED strip many times per second (10 times per second should really be enough). If I do this over WiFi, it will eventually clutter up and make the ESP8266 unresponsive. I need to send the colors as hex, then convert them into usable values (HEX to RGB). Something tells me that's going to cost a lot of resources and the MCU is therefore spending a lot of time just converting the colors into RGB values. Here's a pseudo code example of what I am trying to achieve:
void loop() {
if(Serial.available()) {
if(Serial.read().first(8) == "0xABCDEF") {
//0xABCDEF is basically my indicator saying "this is for individual LEDs"
//Serial.read() can now be something like 0xABCDEF FF0000 00FF00 0000FF FFFFFF 000000
char* colors[] = Serial.read().split(" ");
colorLED(colors);
}
}
}
void colorLED(colors) {
for(i = 1; i < colors.length; i++) {
strip.SetPixelColor(i, color[i]);
}
}
I hope this example makes sense. I can send a serial command like 0xABCDEF FF0000 00FF00 0000FF FFFFFF 000000
. 5 colors in HEX.
My real question is: How do I take a lot of inputs like above (or another way) and turn them into strings, so I can convert them to RGB? Is there a better way to send commands (like pure RGB values? but remember I need to send many)?. Here is how I convert my colors into RGB:
//hexColor can be "FF0000"
int number = (int)strtol(&hexColor[0], NULL, 16);
int r = number >> 16;
int g = number >> 8 & 0xFF;
int b = number & 0xFF;