Back to Parent

// name the pins
int ledPin1 = D2;
int ledPin2 = D4;

void setup()
{
   // Configure the pins to be outputs
   pinMode(ledPin1, OUTPUT);
   pinMode(ledPin2, OUTPUT);

   // Initialize both the LEDs to be OFF
   digitalWrite(ledPin1, LOW);
   digitalWrite(ledPin2, LOW);
   
    //Register our Particle function here
   Particle.function("led1", ledControl1);
   Particle.function("led2", ledControl2);
}
void loop()
{
   // Nothing to do here
}
//control LED 1
int ledControl1(String command)
{
   int state = LOW;

   // find out the state of the led
   if(command == "HIGH"){
       state = HIGH;
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin1, state);
   return 1;
}
//control LED 2
int ledControl2(String command)
{
   int state = LOW;

   // find out the state of the led
   if(command == "HIGH"){
       state = HIGH;
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

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