Arduino Knight Rider KITT Lights

After I had the LEDs plugged into my breadboard for the watch project I’m working on I couldn’t help but make a quick sketch that flashes the lights like the light on KITT from Knight Rider.

 

The code is very simple.  First we just set up all of the pins we use as output pins:

void setup(){
//Set the pins we use as OUTPUT
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}

The next and last thing we do is turn on and off the lights in sequence with a small delay in between each like so:

void loop(){
//Flash from the lower numberd pins to the higher numbered ones...
digitalWrite(3, HIGH);
delay(80);
digitalWrite(2, LOW);
delay(80);
digitalWrite(4, HIGH);
delay(80);
digitalWrite(3, LOW);
delay(80);
digitalWrite(5, HIGH);
delay(80);
digitalWrite(4, LOW);
delay(80);
digitalWrite(6, HIGH);
delay(80);
digitalWrite(5, LOW);
delay(80);
digitalWrite(7, HIGH);
delay(80);
digitalWrite(6, LOW);
delay(80);
digitalWrite(8, HIGH);
delay(80);
digitalWrite(7, LOW);
delay(80);
//and back the other way again
digitalWrite(7, HIGH);
delay(80);
digitalWrite(8, LOW);
delay(80);
digitalWrite(6, HIGH);
delay(80);
digitalWrite(7, LOW);
delay(80);
digitalWrite(5, HIGH);
delay(80);
digitalWrite(6, LOW);
delay(80);
digitalWrite(4, HIGH);
delay(80);
digitalWrite(5, LOW);
delay(80);
digitalWrite(3, HIGH);
delay(80);
digitalWrite(4, LOW);
delay(80);
digitalWrite(2, HIGH);
delay(80);
digitalWrite(3, LOW);
delay(80);
}

This could also be done much more efficiently would be much easier to change the number of and position of the lights or the speed the array blinks at just using the loop and incrementing the value of the pins being set high or low.  A while loop could even be used in the set up to make the pins all output pins and the highest and lowest value pins as well as the speed could all be defined at the top of the sketch.  Maybe I’ll code that up sometime and post it but as this sketch stands now it is really just a glorified Arduino “Hello World.”

Here is the source in a .zip folder: Knight Rider KITT Lights Arduino Sketch.

3 thoughts on “Arduino Knight Rider KITT Lights”

  1. I like your thinking. I learned about transistors from a college textbook I traded a co-worker for a guitar years ago. I went to Radio Shack and bought the parts to create a little circuit that when you placed your finger on the brass button, the harder you pressed, the brighter the LED would light. It really got my adrenalin pumping. But, sadly, I’ve not done anything since in electronics.
    In reading your project list it comes to mind that maybe one day soon Genie will have an app that will allow us to open our garage doors with our phones. Or, maybe someone like you or me can invent a circuit board to install into their openers, naw, don’t think it is possible, or is it. I don’t know enough about cell phones and what all the radio transmitter in them can do. I suppose it could be possible but Genie would make it a premium price for that model I’m sure.

    Oh, I found you through your apps in the marketplace of course.
    Paul in Tampa
    7/13/2011

  2. Thanks for the comment, Paul. I really enjoy the mix of creativity and problem solving that electronics allow me to express. If you’re interested in getting back into electronics there are a lot of great resources on the web both for instruction and sourcing affordable short runs of components. Be sure to tell us about your next project.

Leave a Reply