Back to Parent

// version 3
// On the basis of Version 2, two LEDs will alternate to blink, each blinks the passed-in number of times

int ledPinOr = D2;
int ledPinBl = D4;


void setup() {
    //Register our Particle function here
    Particle.function("ledControl", ledControl);
    
    // configure the pins to be outputs
    pinMode(ledPinOr, OUTPUT);
    pinMode(ledPinBl, OUTPUT);
    
    // initialize both the LEDs to be OFF
    digitalWrite(ledPinOr, LOW);
    digitalWrite(ledPinBl, 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);
            digitalWrite(ledPinBl, LOW);
            delay(500);
            digitalWrite(ledPinOr, LOW);
            digitalWrite(ledPinBl, HIGH);
            delay(500);
        }
        digitalWrite(ledPinBl, LOW);
    } 
    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