Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Created September 23, 2015 15:35
Show Gist options
  • Save tncbbthositg/4a1fd2620a33c0c18d7f to your computer and use it in GitHub Desktop.
Save tncbbthositg/4a1fd2620a33c0c18d7f to your computer and use it in GitHub Desktop.
Basic tri-color LED control with hex colors.
playColor(0x000000); // black
playColor(0xFFFFFF); // white
playColor(0xFF0000); // red
playColor(0x00FF00); // green
playColor(0x0000FF); // blue
playColor(0xFFFF00); // yellow
playColor(0x00FFFF); // cyan
playColor(0xFF00FF); // magenta
void writeColor(long color) {
int red = (color & 0xFF0000) >> 16;
int green = (color & 0xFF00) >> 8;
int blue = (color & 0xFF);
writeColorComponent(RED, red);
writeColorComponent(GREEN, green);
writeColorComponent(BLUE, blue);
}
void writeColorComponent(int color, int value) {
if (COMMON_ANNODE) {
value = 255 - value;
}
analogWrite(color, value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment