Back to Parent

// name the pins
int ledPin = D2;

void setup()
{
    // Configure the pins to be outputs
    pinMode(ledPin, OUTPUT);

    // Initialize both the LEDs to be OFF
    digitalWrite(ledPin, LOW);
    
    //Register our Particle function here
    Particle.function("ledb", ledBlink);
}

void loop()
{
    // Nothing to do here
}

int ledBlink(String cntInput)
{
    int cnt = atoi(cntInput);
    if (cnt <= 0){
        return -1;
    }
    for(int i = 0; i < cnt; i++){
        // First... On
        digitalWrite(ledPin, HIGH);   // Turn ON the LED pins
        delay(1000);  
        // Now... Off
        digitalWrite(ledPin, LOW);   // Turn OFF the LED pins
        delay(1000);               // Wait for 500mS = .5 second
    }
    // Make sure the LEDs to be OFF
    digitalWrite(ledPin, LOW);
    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