Back to Parent

//exercise2 string pass the number of times you would like it to blink
//Set the function to blink that number of times
int led1 = D2;
int value = 0;

void setup() {

    pinMode( led1, OUTPUT);
    digitalWrite(led1, LOW);
    Particle.function("ledn", ledControl);
}

void loop() {
}

int ledControl(String command)
{
   int state = LOW;
   value = command.toInt();
   if(value > 255)return -1;
   if(value < 0)return -1;
   else{
        for (int i = 0; i < value; i++){
           digitalWrite(led1,HIGH);
           delay(500);
           digitalWrite(led1,LOW);
           delay(500);}
         }
	state = LOW;

   // write to the appropriate pin
   digitalWrite(led1, 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