Back to Parent

//Exercise 2_1

int ledPin = D2;

void setup() {
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);
    Particle.function("ledControl", myLedControl);
}

void loop() {

}

int myLedControl(String command) {
    int state = LOW;
    if (command == "ON") {
        for(int i = 0; i <= 3; i++) {
            if(i % 2 == 0) {
                state = HIGH;
                digitalWrite(ledPin, state);
                delay(500);
            } else {
            state = LOW;
            digitalWrite(ledPin, state);
            delay(500);
            }
        }
        return 1;
    } else if(command == "OFF") {
        state = LOW;
        digitalWrite(ledPin, state);
        return -1;
    }
    return 0;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0