Back to Parent

//Cloud Control: Exercise 1
// declare a variable and load it with value
int ledPin = D2;

void setup() {
    // set D2 as output pin
    pinMode(ledPin, OUTPUT);
    // led to be off at start
    digitalWrite(ledPin, LOW);
    //Register our Particle function here
    Particle.function("led", ledControl);
}

void loop() {
}

int ledControl(String command)
{
  int state = LOW;
  // blinking the number of times mentioned
  if(command == "HIGH"){
      // blink 3 times
      for (int i=1; i<4; i++){
          digitalWrite(ledPin, HIGH);
          delay(500);
          digitalWrite(ledPin, LOW);
          delay(500);
      }
  }else if(command == "LOW"){ 
	   state = LOW;
  }else{
	   return -1;
  }

  // write to the appropriate 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