Back to Parent

// Making the light blink every 3 seconds
// 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() {
   // Blink the LED every 3 seconds
   digitalWrite(ledPin, HIGH); // Turn ON the LED
   delay(3000);                // 3 Sec Delay
   digitalWrite(ledPin, LOW);  // Turn OFF the LED
   delay(3000);                // 3 Sec Delay
}

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

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

   // Write to 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