My First Arduino project - Improved Knightrider!

Afternoon all, I recently got my first arduino and just wanted to stomp around with it as you do. I, like most of us love the knightrider sequence so I saw the little project listed on the main site there and figured I wanted something that looked more authentic with a fading “tail” behind the main trail.

Eager to use arduino’s PWM pins I set out to write something to do what I was looking for.

Pictures and video to follow shortly, but here’s the code:

Just hook 6 leds to Pins 3,5,6,9,10 and 11 and let the code do the rest :3

the default code here lets you get away with not using resistors, for lazy blokes who can’t be bothered hunting down enough of them or don’t want to wire them all in.

//Knightrider with fading by J Stainton.

int ledpin[] ={3,5,6,9,10,11}; //organize all PWM pins neatly.
int n = 0; //speed counter.
int i =0; // repeater.
int value[] ={0,0,0,0,0,0}; //lighting amount array for faders

void setup() 
   //nothing to set up

void loop()
  //time codes for light sequence.
  //I designed this to very flexible you could put anything here
  //this particular sequence presents a nice nightrider effect.
  // 100 = 39% power. I was too lazy to find enough
  //resistors to run my 20ma LEDs at full power.
  //change these to 255 if you have properly limited resistors.
  if(n == 100){value[0]=100;}
  if(n == 200){value[0]=100;}
  if(n == 300){value[1]=100;}
  if(n == 400){value[2]=100;}
  if(n == 500){value[3]=100;}
  if(n == 600){value[4]=100;}
  if(n == 700){value[5]=100;}
  if(n == 800){value[5]=100;}
  if(n == 900){value[4]=100;}
  if(n == 1000){value[3]=100;}
  if(n == 1100){value[2]=100;}
  if(n == 1200){value[1]=100;}
  if(n >= 1200){n =0;}
  //fade all pins
  for (i  = 0; i <=5; i++)
    if(value[i] >= 5){ value[i]-=1;}
    else if (value[i] < 5) { value[i]=0;}
 //write to all pins
 for (i  = 0; i <=5; i++)
     analogWrite(ledpin[i], value [i]);
   n+=5; // time stepper. Tweak at your own risk.
   delay(10); //speed modifier. Tweak at your own risk!

Knightrider is fine, but don't start building Cylons :)

ha-ha! it's only a matter of time now! muahahaha!

As the borg would say "Resistors are futile"

Oh no! Are Arduinos Cylon Neurons? Nice effect, Kit Lives!

Oh no! Are Arduinos Cylon Neurons?

no, cylons use PICs

no, cylons use PICs

Glad that's cleared up. I was listening to a podcast by an Aussie engineer last night who probably agrees with you. I think it was the 24F series he was reviewing, but he stated that the hardware errata was just "crazy" and to be sure to read through all the pages when your programming has oddball problems, it may not be you that messed up!

no, cylons use PICs

Actually, Cylons use Intel Core2 processors running windows. It's a common misconception because the peformance of a PIC is comparable when you factor in windows bloat.

Given the serious problems Galactica has with viruses, they are the ones that must be using Windows.

So… any vids of this in action?

Works cool

here is a video of it

Nice. It will need at least 20 LED's to get the full effect I think.