// name the pins
int ledPin = D6;
// 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);
// Make the variable 'ledValue' available through
// the Particle cloud as 'brightness'
Particle.variable("brightness", ledValue);
// Set up pin for output
pinMode(ledPin, OUTPUT);
}
void loop()
{
// Nothing to do here
}
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!
You must login before you can post a comment. .