// RGB LED
int redPin = D2;
int greenPin = D3;
int bluePin = D4;
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Particle.function("led", ledControl);
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
void loop()
{
}
int ledControl(String command)
{
String colors[3];
colors[0]="";
colors[1]="";
colors[2]="";
int index = 0;
for(int i = 0; i < command.length(); i++)
{
if(index < 3)
{
char c = command.charAt(i);
colors[index] += c;
if(c == ',') index++;
}
}
redValue = colors[0].toInt();
greenValue = colors[1].toInt();
blueValue = colors[2].toInt();
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
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. .