Back to Parent

// name the pins
int ledPinR = D2;
int ledPinB = D3;

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

   // Initialize the LED to be OFF
   digitalWrite(ledPinR, LOW);
   digitalWrite(ledPinB, LOW);
   
   //Register our Particle function here
   Particle.function("ledR", ledControlR);
   Particle.function("ledB", ledControlB);

}


void loop() {

}


// Exercise 3

// function to control red LED
int ledControlR(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(ledPinR, state);
   return 1;
}

// function to control blue LED
int ledControlB(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(ledPinB, 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