Blinking LED Breadboard

Assignment: Introduction to Arduino and Physical Computing

Collaborators:

Description

Used the Arduino to control the blinking of a light emitting diode. Made the LED blinking speed variable; the blinking speeds up and then slows down repeatedly.

Components Used

 

  • Light Emitting Diode (LED)
  • Resistor

Arduino Code

/*
  Blink!
 
 Turns on an LED on for two seconds, off for two seconds, then
 decreases and increases the amount of delay time.
 The LED blinks faster, then slows down, and repeats.
 
 The circuit:
 * LED connected from digital pin 13 to ground.
 
 based on an orginal by H. Barragan for the Wiring i/o board
 
 */

int ledPin =  13;    // LED connected to digital pin 13
int del = 2000;      // a specified delay time
// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                     
{
  while (del > 100) {
    digitalWrite(ledPin, HIGH);  // set the LED on
    delay(del);                  // wait for a delay time
    digitalWrite(ledPin, LOW);   // set the LED off
    delay(del);                  // wait for the delay time
    del = del - (del/20);      // decrease the delay time
  }
  while (del < 2000) {
    digitalWrite(ledPin, HIGH);  // set the LED on
    delay(del);                  // wait for a delay time
    digitalWrite(ledPin, LOW);   // set the LED off
    delay(del);                  // wait for the delay time
    del = del + (del/20);      // increase the delay time
  }
}