//bonus built-in RGB
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
void setup()
{
//Register our Particle function to allow
// Make the variable 'ledValue' available through
// the Particle cloud as 'brightness'
Particle.function("led", ledControl);
// Set up pin for output
Particle.variable("Red", redValue);
Particle.variable("Green", greenValue);
Particle.variable("Blue", blueValue);
}
void loop()
{
}
int ledControl(String command)
{
String colors[3];
int firstCommaIndex = command.indexOf(',');
int secondCommaIndex = command.indexOf(',', firstCommaIndex+1);
colors[0] = command.substring(0, firstCommaIndex);
colors[1] = command.substring(firstCommaIndex+1, secondCommaIndex);
colors[2] = command.substring(secondCommaIndex+1);
redValue = colors[0].toInt();
greenValue = colors[1].toInt();
blueValue = colors[2].toInt();
// We need to say we'll be controlling the RGB led
RGB.control(true);
// set it to white
RGB.color( redValue,greenValue,blueValue);
// wait 3 seconds
delay( 3000 );
// return control of the RGB led to Particle
RGB.control(false);
return 1;
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .