LED blink sequence

This example is for Wiring version 0024+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Swing LEDs by BARRAGAN http://barraganstudio.com

Demonstrates the use of digital pins to turn on one light (LED) at a time in a row of 8 one after the other.

 
int which = 0;              // variable the keeps which light must be turn on next

void setup() 
{
  for(int i=0; i<8; i++) {  // initializes pins 0 to 7 as outputs
    pinMode(i, OUTPUT);  
  }
}

void loop() 
{
  turn_all_off();              // turns all lights off
  digitalWrite(which, HIGH);   // sets on the current light on
  delay(200);                  // waits for 200 milli seconds
  which = which + 1;           // increment the variable to turn on the next one next time
  if(which > 7)                // check for the range, if greater then 7 goes back to 0
  {
    which = 0;
  }
}

void turn_all_off() {      // function to turn off all the lights                          
  int i;                   // connected to digital pins 0 to 7
  for(i=0; i<8; i++) {
    digitalWrite(i, LOW);  
  }
}