int ledPin1 = D2;
int ledPin2 = D3;
// create a variable to store the
// current brightness of the LED
int ledValue = 0;
void setup() {
//Register our Particle function to allow
// Control of the LED
Particle.function("led", ledControl);
Particle.variable("brightness", ledValue);
// Set up pin for output
pinMode(ledPin2, OUTPUT);
pinMode(ledPin1, OUTPUT);
}
void loop() {
}
int ledControl(String command)
{
// Convert the passed variable to an integer
ledValue = command.toInt();
// Check it is a valid number
if( ledValue > 255 ) return -1;
if( ledValue < 0 ) return -1;
if (ledValue < 255){
int led2Brightnes= (255 - ledValue);
for(int j=led2Brightnes; j>=0; j--){
analogWrite(ledPin2, j);
delay(10);
}
for(int i=ledValue; i>=0; i--){
analogWrite(ledPin1, i);
delay(10);
}
}
// Return 1 to say completed successfully
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. .