/* Knight Rider 4 * by Desta Courtney questions desta@usLEDsupply.com parts of code based on "Knight Rider 3" by David Cuartielles * * This project is intended to make a bunch of small leds in a row flash back and forth to look like the car on knight rider * In this case the hardware is 8 mini blue LED modules (from usLEDsupply.com) running at 12v DC so a Darlington Transistor Array (ULN2803A) is needed and connected to the * 8 output pins on the arduino it is also fed (-) 12v to the GND pin and all the leds are fed (+) 12v so only the (-) is switched with the (ULN2803A) * the (ULN2803A) is rated at 500mA/Ch and there are 8Ch but we are only driving 2 20mA leds per channel so there is plenty of power left * I also used a pot on analog input (0) so you can change the speed of the effect on the fly without having to reprogram it (it is also mapped to an adjustable range for better control) * Enjoy * There is a video of it working on YouTube (just search "usLEDsupply" or "Knight Rider Arduino" and you should find it) or instructions on http://fritzing.org/profiles/usLEDsupply/ */ int pinArray[] = {2, 3, 5, 6, 9, 10, 11, 12}; // lists the pins the leds are attached to byte count = 0; // used so the program knows where it is in the sequnce int timer = 50; // is used for the map function // you can adjust the numbers below to set te max and min for the speed adjustment int x = 0; // sets the max speed (0 = fast) the lower the number the faster it can go int y = 100; // sets the min speed (100 = slow) the higher the number the slower it can go void setup(){ for (count=0;count < 8;count++) { // sets all the pins in the array as outputs pinMode(pinArray[count], OUTPUT); // sets all the pins in the array as outputs } } void loop() { for (count=0;count < 7;count++) { // cycles threw all the leds in the array digitalWrite(pinArray[count], HIGH); // turns the first led on delay(timer); // sets the delay (for how fas it will go) digitalWrite(pinArray[count + 1], HIGH); // turns the next led on delay(timer); // sets the delay (for how fas it will go) digitalWrite(pinArray[count], LOW); // turns it back off delay(timer); // sets the delay (for how fas it will go) timer = analogRead(0); // reads the pot and sets the timer to the value timer = map(timer, 0, 1023, x, y); // maps the timer value to the max and min vaues set above with x and y } for (count=7;count > 0;count--) { // same thing but in reverse so it will end up going back and forth digitalWrite(pinArray[count], HIGH); delay(timer); digitalWrite(pinArray[count - 1], HIGH); delay(timer); digitalWrite(pinArray[count], LOW); delay(timer); timer = analogRead(0); // reads the pot and sets the timer to the value (this is the same as above but is reading it again so you don't have to waut as long to see the speed changes) timer = map(timer, 0, 1023, x, y); // maps the timer value to the max and min vaues set above with x and y } }