Back to Parent

int ledPin = D2;
int ledValue = 0;

void setup() {
    Particle.function("led", ledControl);
    Particle.variable("brightness", ledValue);
    pinMode(ledPin, OUTPUT);


}

void loop() {
digitalWrite(ledPin, HIGH);
     delay(1000);
    
     digitalWrite(ledPin, LOW);
     delay(1000);
     
}

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;

   // Use PWM to set the brightness
   // of the LED
   analogWrite(ledPin, ledValue);

   // 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!

0