// Blink an LED
int ledPin = 13; // Digital output pin num 13
int dTime = 500; // this is a delay of one second
int counter = 0; // Keep a counter to change the speed every step
int speedInc = 100; // Store the increase of delay in a variable
void setup()
{
// Set the digital pin as output
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(dTime); // Let the light burn for a while
digitalWrite(ledPin, LOW);
delay(dTime); // Let the light be turned off for a while
// Keep the counter for every step in the loop
counter = counter + 1;
// Every 10 steps switch the speed increment to positive or negative
if(counter % 10 == 0) {
speedInc = speedInc * -1;
}
// Increase (or decrease) the delay
// Led will flash slower and longer or faster and shorter
dTime = dTime + speedInc;
}
- Login to post comments