//Exercise 2_2
int ledPin = D2;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Particle.function("ledControlByTimes", myLedControl);
}
void loop() {
}
int myLedControl(String command) {
int times = command.toInt();
int state = LOW;
for(int i = 1; i <= times * 2; i++) {
if(i % 2 == 0) {
state = HIGH;
digitalWrite(ledPin, state);
delay(500);
} else {
state = LOW;
digitalWrite(ledPin, state);
delay(500);
}
}
digitalWrite(ledPin, LOW);
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. .