Driving 8 Leds to simulate the the Knight Rider car of the TV show.
A very simple algorithm was implemented.
The Sketch:
/* KnightR8L.pde Arduining.com 1 MAY 2011 Driving 8 Leds to emulate the Knight Rider car. Leds connected to the digital pins (0~7). */ byte n=0; //The number to be displayed (8 bits). void setup(){ for(int i=0;i<8;i++){ // Digital pins 0~7 as outputs. pinMode(i,OUTPUT); } } void loop(){ for(n=1;n<128;n = n << 1){ PORTD= n; delay(132); // delay(analogRead(0)/4); } for(n=128;n>1;n = n >> 1){ PORTD= n; delay(132); // delay(analogRead(0)/4); } }
A potentiometer was used to adjust the scanning frequency.
A delay dependent of the analog input 0 was used.This part is commented in the final code.
See the Youtube Video: