Back to Parent

// version 1  
// On the basis of Version 0, the LED will blink 3 times before it is turned on/off

int ledPinOr = D2;


void setup() {
    //Register our Particle function here
    Particle.function("ledControl", ledControl);
    
    // configure the pins to be outputs
    pinMode(ledPinOr, OUTPUT);
    
    // initialize both the LEDs to be OFF
    digitalWrite(ledPinOr, LOW);

}

void loop() {
}

int ledControl(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(ledPinOr, LOW);
    for (int i = 1; i <= 3; i++) {
    digitalWrite(ledPinOr, HIGH);
    delay(500);
    digitalWrite(ledPinOr, LOW);
    delay(500);
    }
    digitalWrite(ledPinOr, 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!

0