Back to Parent

// version 2
// Passing in a number, the LED will blink the passed-in number of times

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) {
    
    // find out the state of the LED
    int value = command.toInt();

    if( value > 0 ) {
        for (int i = 1; i <= value; i++) {
            digitalWrite(ledPinOr, HIGH);
            delay(500);
            digitalWrite(ledPinOr, LOW);
            delay(500);
        }
    } 
    else {
        return -1;
    }

    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