Back to Parent

//connected LED - 03

// Define the pins
int ledPinOrange = D2;
int ledPinRed = D3;

void setup()
{
    // Configure the pins as outputs
    pinMode(ledPinOrange, OUTPUT);
    pinMode(ledPinRed, OUTPUT);

    digitalWrite(ledPinOrange, LOW);
    digitalWrite(ledPinRed, LOW);

    Particle.function("led", ledControl);
}

void loop()
{
}


int ledControl(String command)
{   
    int blinkInterval = atoi(command);
    blinkLeds(blinkInterval);
    return 1; 
}

void blinkLeds(int delayTime)
{
    for (int i = 0; i < 50; i++) 
    {
        // Red on, orange off
        digitalWrite(ledPinOrange, LOW);
        digitalWrite(ledPinRed, HIGH);
        delay(delayTime);

        // Red off, orange on
        digitalWrite(ledPinOrange, HIGH);
        digitalWrite(ledPinRed, LOW);
        delay(delayTime);
    }

    // Turn off LEDs after blinking
    digitalWrite(ledPinOrange, LOW);
    digitalWrite(ledPinRed, LOW);
}
Click to Expand

Content Rating

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

0