//connectedled:exercise 3: add a second LED to the circuit, control both LEDs remotely
int led1 = D2;
int led2 = D3;
int value = 0;
void setup() {
//Register Particle function here
Particle.function("led", ledControl);
pinMode (led1, OUTPUT);
digitalWrite(led1, LOW); //LED 1 initial state to be off
pinMode (led2, OUTPUT);
digitalWrite(led2, LOW); //LED 2 initial state to be off
}
void loop(){
//nothing to do here
}
int ledControl (String command)
{
int state = LOW;
//find out the state of the led
if (command == "1") {
digitalWrite(led1, HIGH);
}
if (command == "2"){
digitalWrite(led2, HIGH);
}
if (command == "0"){
state = LOW;
}
if (command == "-1"){
digitalWrite(led1, LOW);
}
if (command == "-2"){
digitalWrite(led2, LOW);
}else{
return -1;
}
//write to the appropriate pin
digitalWrite(led1, state);
digitalWrite(led2, 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. .