Back to Parent

// Turning the light on and connecting it to the cloud
// Name and assign the pins
int ledPin = D3;

void setup() {
   // Configure the pin to be an output
   pinMode(ledPin, OUTPUT);

   //  LED to be OFF
   digitalWrite(ledPin, LOW);

   // Register cloud function here
   Particle.function("led", ledControl);
}

void loop() {
}

int ledControl(String command) {
   int state = LOW;

   // LED state
   if (command == "HIGH") {
	   state = HIGH;
   } else if (command == "LOW") { 
	   state = LOW;
   } else {
	   return -1; // Invalid command
   }

   // Write to the pin
   digitalWrite(ledPin, state);
   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