Back to Parent

// 5 blinks and 3 sec delay
// 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 5 times then stop for 3 sec
   for (int i = 0; i < 5; i++) {
       digitalWrite(ledPin, HIGH); // Turn ON the LED
       delay(500);                 // 0.5 Sec Delay
       digitalWrite(ledPin, LOW);  // Turn OFF the LED
       delay(500);                 // 0.5 Sec Delay
   }
   delay(3000);                    //  3 Sec Delay after 5 blinks
}

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