Back to Parent

// version 0
// Passing in a "HIGH" string will turn on the orange LED; passing in a "LOW" string will turn off the orange LED

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, 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