Back to Parent

//fuction exercise 3

int ledPin1 = D1;
int ledPin2 = D2;

void setup() {

    pinMode( ledPin1, OUTPUT );
    pinMode( ledPin2, OUTPUT );
    digitalWrite( ledPin1, LOW );
    digitalWrite( ledPin2, LOW );
    //LED is initially turned off.
    
    Particle.function( "led", ledControl );
    //register function

}

int ledControl( String command ) {
    
    int state = LOW;
    
        if( command == "CALL" ) {
        
        for ( int i = 0; i < 5; i++ ) {
        
        digitalWrite( ledPin1, HIGH );
        digitalWrite( ledPin2, HIGH );
        delay( 300 );
        digitalWrite(ledPin1, LOW );
        digitalWrite(ledPin2, LOW );
        delay( 300 );
        }
    }    
    
    else if( command == "CALL1" ) {
        
        for ( int i = 0; i < 5; i++ ) {
        
        digitalWrite( ledPin1, HIGH );
        delay( 300 );
        digitalWrite(ledPin1, LOW );
        delay( 300 );
        }
    }    
    
    else if( command == "CALL2" ) {
        
        for ( int i = 0; i < 5; i++ ) {
        
        digitalWrite( ledPin2, HIGH );
        delay( 300 );
        digitalWrite(ledPin2, LOW );
        delay( 300 );
        }
    }
    
    
    else {
        return -1;
    }
    
    digitalWrite( ledPin1, state );
    digitalWrite( ledPin2, state );
    return 1;
}

void loop() {

}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0