Back to Parent

//Connected LED Exercise 2: Make the LED blink # of times then turn off

int ledPin1 = D2;

void setup() {
  pinMode(ledPin1, OUTPUT);
  
  // Initialize both the LEDs to be OFF
   digitalWrite(ledPin1, LOW);
   
   Particle.function("Number of red led blinks", ledControl1);
}
void loop() {
  
 
}

int ledControl1(String command)
{
   int value = command.toInt();

   // find out the state of the led
   if(value > 0)
   {
	   for (int i = 0; i < value; i++) 
        {
            digitalWrite(ledPin1, HIGH); 
            delay(500);               
            digitalWrite(ledPin1, LOW);   
            delay(500);
        }
   }
   else
   {
	   return -1;
   }
   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