It’s really simple, and just toys with the LED, but it was still fun to mess with. Based on Circ01 in the SparkFun Inventor’s book.


int ledPin = 9;

void setup() {
 // Tells Arduino board where LED is and how to treat it. 
 pinMode(ledPin, OUTPUT); 
}

void loop() {
  /**
  * Loops through analog stages at 25 pts/step
  * Gives me an idea of various brightness.
  * At 255, max voltage is reached (~5v), so we exit loop.
  */
  for (int a = 0; a <=250; a += 25)
  {
    analogWrite(ledPin, a);
    delay(1000);
  }
  
  // This should give a glowing effect.
  for(int i = 0; i<= 255; i++)
  {
   analogWrite(ledPin, i);
   delay(15); 
  }
  
  // This should give a dimming effect.
  for(int j = 255; j >=0; j--)
  {
    analogWrite(ledPin, j);
    delay(15);  
  }
  
  //digitalWrite only does ON/OFF functionality.
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
} //end of loop(), which is guts of Arduino program

The loop() method does just that–loops until Arduino is powered down.