Back to Parent

//Exercise 1: LED Blink 3 times

int ledPin = D2;
// int ledPin2 = D3;

void setup() {
  pinMode(ledPin, OUTPUT);
//   pinMode(ledPin2, OUTPUT);
  
  // Initialize both the LEDs to be OFF
   digitalWrite(ledPin, LOW);
//   digitalWrite(ledPin2, LOW);
   
   Particle.function("led", ledControl);
}

void loop() {
  
 
}

int ledControl(String command)
{
   int state = LOW;

   // find out the state of the led
   if(command == "HIGH")
   {
	   for (int i = 0; i < 3; i++) 
        {
            digitalWrite(ledPin, HIGH); 
            delay(500);               
            digitalWrite(ledPin, LOW);   
            delay(500);
        }
	   state = HIGH;
   }
   else if(command == "LOW")
   { 
	   state = LOW;
   }
   else
   {
	   return -1;
   }

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