Back to Parent

//Cloud Control: Exercise 2
// 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;
  // string to integer
  int num = command.toInt();
  // blinking the number of times mentioned
  if(num > 0){
      for (int i=1; i<num+1; i++){
      digitalWrite(ledPin, HIGH);
      delay(500);
      digitalWrite(ledPin, LOW);
      delay(500);
  }
  }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