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);
}