Monday, May 3, 2010

Task 20: from 10ms to 1 sec then back down again

int ledPin = 13; // LED pin
int del = 10; // Starting Delay
bool dirUp = false; // are we increasing or decreasing

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(del); // wait for a second
if( dirUp ) {
if((del++) == 1001) {
del = 1000;
dirUp = false;
}
} else {
if((del--) == 9) {
del = 10;
dirUp = true;
}
}
}

No comments:

Post a Comment