int ledPin1 = D2;
int ledPin2 = D3;
void setup() {
// Configure the pins to be outputs
pinMode(ledPin1, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(ledPin1, LOW);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin2, LOW);
Particle.function("led1", ledControl1);
Particle.function("led2", ledControl2);
}
void loop() {
// Nothing to do here
}
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;
}
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!
You must login before you can post a comment. .