Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spark Core rgb led
int redPin = A4;
int greenPin = A0;
int bluePin = A1;
void setup()
{
Spark.function("rgb", rgbControl);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
void loop()
{
}
int rgbControl( String hex )
{
const char *hexstring = hex.c_str();
int number = (int) strtol( &hexstring[0], NULL, 16);
int r = number >> 16;
int g = number >> 8 & 0xFF;
int b = number & 0xFF;
analogWrite(redPin, 255 - r);
analogWrite(greenPin, 255 - g);
analogWrite(bluePin, 255 - b);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.