Skip to content

Instantly share code, notes, and snippets.

@thisisjofrank
Created May 21, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisisjofrank/2f1c09746be379f7d758e82f2826a113 to your computer and use it in GitHub Desktop.
Save thisisjofrank/2f1c09746be379f7d758e82f2826a113 to your computer and use it in GitHub Desktop.
process the message once received
// Example = 001#aa00ff
// Split message at '#' into pixel_number and hex_colour
const auto pixel_end = framedata.indexOf('#', 0);
const auto pixel_number_str = framedata.substring(0, pixel_end);
const auto hex_colour_str = framedata.substring(pixel_end + 1);
auto pixel_number = pixel_number_str.toInt();
char hex_code[7];
int r, g, b = 0;
// Convert hex value to RGB
hex_colour_str.toCharArray(hex_code, 7);
sscanf(hex_code, "%02x%02x%02x", &r, &g, &b);
// Update the lights on the display with the pixel number and rgb values
lights::update_pixel(pixel_number, r, g, b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment