Back to Parent

//first sketch - exploration - 3 - 1

int redLedPin = D3;
int oraLedPin = D2;

void setup()
{
    pinMode(oraLedPin, OUTPUT);
    pinMode(redLedPin, OUTPUT);
}

void loop()
{
    speedUp();
    slowDown();
}

void speedUp()
{
    // gradually speed up 
    for (int i = 0; i < 10; i++) 
    {
        // red on, orange off
        digitalWrite(oraLedPin, HIGH);
        digitalWrite(redLedPin, LOW);
        delay(i * 200);
    
        // red off, orange on
        digitalWrite(oraLedPin, LOW);
        digitalWrite(redLedPin, HIGH);
        delay(i * 200);
    }
}

void slowDown()
{
    // gradually slow doen
    for (int i = 10; i > 0; i--) 
    {
        // red on, orange off
        digitalWrite(oraLedPin, HIGH);
        digitalWrite(redLedPin, LOW);
        delay(i * 200);
    
        // red off, orange on
        digitalWrite(oraLedPin, LOW);
        digitalWrite(redLedPin, HIGH);
        delay(i * 200);
    }
}
Click to Expand

Content Rating

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

0