Back to Parent

//Exercise 2-1

int led = D2;
int status = LOW;

void setup() {
    pinMode (led, OUTPUT);
    Particle.function ("ControlLight", lightControl);
    digitalWrite(led, LOW);
}

void loop() {

}

//Cloud-based control
int lightControl (String command) {
        
    if (command.equals ("on")){
        for (int i = 0; i <= 5; i++){

            if (i % 2 == 0){
                status = HIGH;
                delay(500);     
                digitalWrite (led, status);
            }else{
                status = LOW;
                delay(500);
                digitalWrite (led, status);
            }
            
            
        }

            
        
        return 1;
        
    }else if (command.equals("off")){
        
        status = LOW;
        digitalWrite (led, status);
        return -1;
        
    }else{
    
        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