Knight Rider LED bar

The power switch is mounted on the dashboard and a little 4 AA battery pack under the skelter. A little PCB with lots of wires attached behind the PCB with the LEDs and the whole has been fixed in an old piece of plexiglass. We stripped the LED bar out of an old toy but it would not take much time to build one on a little experiment PCB or breadboard.


Source

If you like to make one yourself, you find the source code below. The code can be compiled using AVR studio and flashed in the microcontroller using ICSP.


You can find the source here.


/*
** Little AVR hack to create Knight Rider Lights LED bar.
** 
** (The MIT License)
** 
** Copyright: Robota Softwarehouse BV
** Written by: Arne Diegenbach
** http://www.robota.nl/en/blog/knight-rider-light-bar-for-skelter
** 
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** 'Software'), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
** 
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
** 
** THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
** 
*/

#include <avr/io.h>
#include <util/delay.h>
 
#define kMaxLed	15

//======================
void ioinit(void);
void led_on(int n);
void led_off(int n);
void new_led_on(int n);
void playLeftToRight(void);
void playRightToLeft(void);
void playInToOut(int single);
void playOutToIn(int single);
void playOddEven(void);
void blueOn(void);
void blueOff(void);
void playTest(void);
void allOff(void);
void flash(void);
//======================

int last = 0;
int gLedDelay = 50;

int main (void)
{
	int i;
	ioinit(); //Setup IO pins and defaults

	while (1)
	{
		playTest();
		allOff();
		for (i = 0; i < 4; i++) {
			playOutToIn(1);
			allOff();
			_delay_ms(100);
			playInToOut(1);
		}
		allOff();
		playOddEven();
		for (i = 0; i < 4; i++) {
			playLeftToRight();
			playRightToLeft();
		}
		allOff();
		for (i = 0; i < 2; i++) {
			playOutToIn(0);
			allOff();
			_delay_ms(100);
			playInToOut(0);
			_delay_ms(100);
		}
		allOff();
		flash();
		allOff();
	}
}

void playTest() {
	int i,j;
	for (i = 0; i < 4; i++) {
		led_off(0);
		led_off(1);
		led_on(2);
		led_on(3);
		led_off(4);
		led_off(5);
		led_on(6);
		led_on(7);
		led_off(8);
		led_off(9);
		led_on(10);
		led_on(11);
		led_off(12);
		led_off(13);
		led_on(14);
		led_on(15);

		blueOn();
		_delay_ms(100);

		led_on(0);
		led_on(1);
		led_off(2);
		led_off(3);
		led_on(4);
		led_on(5);
		led_off(6);
		led_off(7);
		led_on(8);
		led_on(9);
		led_off(10);
		led_off(11);
		led_on(12);
		led_on(13);
		led_off(14);
		led_off(15);
		blueOff();
		_delay_ms(100);
	}
	allOff();
	for (i = 0; i < 8; i++) {
		playInToOut(1);
		blueOn();
		_delay_ms(60);
		blueOff();
		_delay_ms(600);
		blueOn();
		_delay_ms(100);
		blueOff();
		playOutToIn(1);
	}
	allOff();
	for (i = 0; i < 15; i++) {
		for (j = 0; j < 8; j++) {
			if (i % 2) {
				led_on(j);
				led_off(j+8);
			}
			else {
				led_off(j);
				led_on(j+8);
			}
		}
		if (i % 2) {
			blueOff();
		}
		else {
			blueOn();
		}
		_delay_ms(600);
	}
	allOff();
}

void allOff() {
	int i;
	for (i = 0; i <= kMaxLed; i++) {
		led_off(i);
	}
	blueOff();
}

void playLeftToRight() {
	int i;
	for (i = 0; i <= kMaxLed; i++) {
		new_led_on(i);
	}
} 
 
void playRightToLeft() {
	int i;
	for (i = kMaxLed; i >= 0; i--) {
		new_led_on(i);
	}
} 
 
void playOddEven() {
	int i,j;
	for (j = 0; j < 8; j++) {
		for (i = 0; i <= kMaxLed; i++) {
			if (j % 2) {
				if (i % 2) {
					led_on(i);
				}
				else {
					led_off(i);
				}
			}
			else {
				if (i % 2) {
					led_off(i);
				}
				else {
					led_on(i);
				}
			}
		}
		_delay_ms(200);
	}
}

void playOutToIn(int single) {
	int i;
	for (i = 0; i < 8; i++) {
		led_on(i);
		led_on(kMaxLed-i);
		_delay_ms(gLedDelay);
		if (single) {
			led_off(i);
			led_off(kMaxLed-i);
		}
	}
} 

void playInToOut(int single) {
	int i;
	for (i = 7; i >= 0; i--) {
		led_on(i);
		led_on(kMaxLed-i);
		_delay_ms(gLedDelay);
		if (single) {
			led_off(i);
			led_off(kMaxLed-i);
		}
	}
}

void flash() {
	int i, j;
	for (j = 30; j > 1; j--) {
		for (i = 0; i < 16; i++) {
			if (j % 2) {
				led_on(i);
			}
			else {
				led_off(i);
			}
		}
		if (j % 2) {
			blueOff();
		}
		else {
			blueOn();
		}
		_delay_ms(10 + j*10);
	}
}

void ioinit (void)
{
   DDRB  = 0b11111111; //1 = output, 0 = input
   PORTB = 0b00000000;
   DDRC  = 0b11111111;
   PORTC = 0b00000000;
   DDRD  = 0b11111111;
   PORTD = 0b00000000;
}

void new_led_on(int n)
{
	led_off(last);
	led_on(n);
	last = n;
	_delay_ms(gLedDelay);
}
 
void led_off(int n)
{
	switch (n) {
		case 0:
			PORTC |= _BV(PC5);
			break;
		case 1:
			PORTC |= _BV(PC4);
			break;
		case 2:
			PORTC |= _BV(PC3);
			break;
		case 3:
			PORTC |= _BV(PC2);
			break;
		case 4:
			PORTC |= _BV(PC1);
			break;
		case 5:
			PORTC |= _BV(PC0);
			break;
		case 6:
			PORTB |= _BV(PC4);
			break;
		case 7:
			PORTD |= _BV(PORTD1);
			break;
		case 8:
			PORTB |= _BV(PC2);
			break;
		case 9:
			PORTB |= _BV(PC1);
			break;
		case 10:
			PORTB |= _BV(PC6);
			break;
		case 11:
			PORTB |= _BV(PORTB7);
			break;
		case 12:
			PORTD |= _BV(PORTD5);
			break;
		case 13:
			PORTD |= _BV(PORTD6);
			break;
		case 14:
			PORTD |= _BV(PORTD7);
			break;
		case 15:
			PORTB |= _BV(PORTB0);
			break;
	}
}
 
void led_on(int n)
{
	switch (n) {
		case 0:
			PORTC &= ~_BV(PC5);
			break;
		case 1:
			PORTC &= ~_BV(PC4);
			break;
		case 2:
			PORTC &= ~_BV(PC3);
			break;
		case 3:
			PORTC &= ~_BV(PC2);
			break;
		case 4:
			PORTC &= ~_BV(PC1);
			break;
		case 5:
			PORTC &= ~_BV(PC0);
			break;
		case 6:
			PORTB &= ~_BV(PC4);
			break;
		case 7:
			PORTD &= ~_BV(PORTD1);
			break;
		case 8:
			PORTB &= ~_BV(PC2);
			break;
		case 9:
			PORTB &= ~_BV(PC1);
			break;
		case 10:
			PORTB &= ~_BV(PC6);
			break;
		case 11:
			PORTB &= ~_BV(PORTB7);
			break;
		case 12:
			PORTD &= ~_BV(PORTD5);
			break;
		case 13:
			PORTD &= ~_BV(PORTD6);
			break;
		case 14:
			PORTD &= ~_BV(PORTD7);
			break;
		case 15:
			PORTB &= ~_BV(PORTB0);
			break;
	}
}


void blueOn() {
	PORTB &= ~_BV(PC5);
}

void blueOff() {
	PORTB |= _BV(PC5);
}

Need help?
We love to hear from you! Please fill in your details to help you better!
We are here to answer your questions. Please fill in your name and press 'Start Chat'.
Thanks!
We will get back to you as soon as possible!