Sprinting LED

Description:

I used an Arduino-Uno as a microprocessor to light an LED light at a decelerating pace.

Components Used:

  • 1 Arduino
  • 1 LED
  • 1 Resistor (220Ω)
  • 1 Breadboard

Code:

/*
 * Blink
 * 
 */

int ledPin = 13;


int stepFunction(int x, int y){
 //the rate at which the LED will decelerate.
 int result;
 result = x + y;
 return result;
}

int pace = 0;

void setup() {
 // put your setup code here, to run once:
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
}

void loop() {
 // set the running pace for the LED blinking
 int increment = 20; // first, set increment to 20ms. 
 digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
 pace = stepFunction(pace, increment);
 Serial.println(increment);
 delay(pace);
// delay(2000); // wait for a second
 digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
 delay(pace);
// delay(1000); // wait for a second
 increment = pace;
}

Leave a Reply