Fade question

I'm a nerd! And like several beginner Arduino peeps, I'm designing a Knight Rider type scanner. I'm only using 9 LED's at the moment, but want to expand after I fix this code:

I used the code for the pot control, and modified it just a little. I just can't seem to figure out how to make the LED's fade as the next one lights up, like the original K.I.T.T.

Here's what I have so far, if you could be so kind as to help:

/*
Analog Input
This code I found in the public domain. I modified to power 9 LEDs
in the Knight Rider scann sequence.

Created by David Cuartielles
Modified 7 May 2011 by Izzy

*/

int sensorPin = A0; // select the input pin for the potentiometer
int led0Pin = 13; // select the pin for the LEDs
int led1Pin = 12;
int led2Pin = 11;
int led3Pin = 10;
int led4Pin = 9;
int led5Pin = 8;
int led6Pin = 7;
int led7Pin = 6;
int led8Pin = 5;
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPins as an OUTPUT:
pinMode(led0Pin, OUTPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
pinMode(led5Pin, OUTPUT);
pinMode(led6Pin, OUTPUT);
pinMode(led7Pin, OUTPUT);
pinMode(led8Pin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led0Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led0Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led1Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led1Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led2Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led2Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led3Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led3Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led4Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led4Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led5Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led5Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led6Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led6Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led7Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led7Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led8Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led8Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led7Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led7Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led6Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led6Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led5Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led5Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led4Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led4Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led3Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led3Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led2Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led2Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(led1Pin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(led1Pin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);

}

Instead of just turning the LED full on & full off, you need to turn them on with gradually increasing lenght pulses until full on, then do the same to fade out.

You could write this as a couple of loops within a loop:
conceptually:

void loop(){
for (x=1 to 9){
fade up led(x)
fade down led(x)
next x}
for (x = 9 to 1){
fade up led(x)
fade down led(x)
next x}

Then if you want 2 to fade up as 1 fades down, make the code do that:
fade up led(x)
fade down led(x)
fade up led(x+1)
next x

Have to put some checks in to skip fading up #10 if there are only 9.
Fade up & fade down could be for:next loops as well, where you increase the ratio of turn on time to turn off time:
for (fadeup=1 to 10){
digitalWrite (LED, HIGH)
delay (fadeup)
digitalWrite (LED, LOW)
delay (10-fadeup)
next fadeup}

for (fadedown=10 to 1){
digitalWrite (LED, HIGH)
delay (fadedown)
digitalWrite (LED, LOW)
delay (10-fadedown)
next fadedown}

I'm gonna add that to my code today......Thank you for taking the time to help a beginner out....

izzy

Which Arduino are you using? You can only fade LEDs attached to PWM pins. The Uno and Duemilanove only have 6 PWM pins.

Please, before you hurt yourself with all that typing: (uncompiled, untested)

const int sensorPin = A0;    // select the input pin for the potentiometer
const int ledPin[] = {13, 12, 11, 10, 9, 8, 7, 6, 5}; 
#define N_LEDS (sizeof(ledPin) / sizeof(ledPin[0]))

void setup() {
  // declare the ledPins as an OUTPUT:
  for (int i = 0; i < N_LEDS; ++i) {
    pinMode(ledPin[i], OUTPUT);  
  }  
}

void loop() {
  int sensorValue;
  for (int i = 0; i < N_LEDS; ++i) {
    sensorValue = analogRead(sensorPin);    
    digitalWrite(ledPin[i], HIGH);  
    delay(sensorValue);          
    digitalWrite(ledPin[i], LOW);   
    delay(sensorValue);                  
  }

  for (int i = N_LEDS - 1; i >= 0; --i) {
    sensorValue = analogRead(sensorPin);    
    digitalWrite(ledPin[i], HIGH);  
    delay(sensorValue);          
    digitalWrite(ledPin[i], LOW);   
    delay(sensorValue);                  
  }
}

PaulS:
Which Arduino are you using? You can only fade LEDs attached to PWM pins. The Uno and Duemilanove only have 6 PWM pins.

I'm using the Duemilanove, so I think I'm gonna have to add more controlers, or drop my LEDs to the 6 that fade....

AWOL:
Please, before you hurt yourself with all that typing:

And thank you for taking the time to type that for me!

I did totally miss the point of his typing! But, after copying, I realized the length of his code, compared to mine.

I was hoping to build it myself as opposed the DIY kit, that way I can learn a little more.......

By the way, there are some bright members in this forum!

arduino is a little more difficult than I thought! I'm gonna work with this code a little more.

Arduino, such as this one: http://www.instructables.com/id/Arduino-LarsonCylon-Scanner/

I headed over to insructables and copied the code for the larson scanner,and I love the way it scans, I'm gonna play with that code too!