//Exercise 2-3
int led1 = D2;
int led2 = D3;
int status = LOW;
void setup() {
pinMode (led1, OUTPUT);
pinMode(led2, OUTPUT);
Particle.function ("LEDlLight 1", ledControl1);
Particle.function ("LEDlLight 2", ledControl2);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
void loop() {
}
//Cloud-based control
int ledControl1 (String command) {
int i = command.toInt();
for (i = 0; i <= command.toInt() * 2 - 1; i++){
if (i % 2 == 0){
status = HIGH;
delay(500);
digitalWrite (led1, status);
}else{
status = LOW;
delay(500);
digitalWrite (led1, status);
}
}
return i / 2;
}
int ledControl2 (String command) {
int i = command.toInt();
for (i = 0; i <= command.toInt() * 2 - 1; i++){
if (i % 2 == 0){
status = HIGH;
delay(500);
digitalWrite (led2, status);
}else{
status = LOW;
delay(500);
digitalWrite (led2, status);
}
}
return i / 2;
}
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. .