Home Code Knightrider LED effect

Knightrider LED effect

by shedboy71

The knightrider / larson / cylon effect

Schematic

knight rider

Code

int pinArray[] = { 2, 3, 4, 5, 6, 7, 8, 9};
int count = 0;
int timer = 10;
 
void setup()
{
  for (count=0;count<8;count++) 
  {
    pinMode(pinArray[count], OUTPUT);
  }
}
 
void loop() 
{
  for (count=0;count<7;count++) 
  {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
  for (count=7;count>0;count--) 
  {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count - 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
}
Share

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More