Home Code Knightrider LED effect

Knightrider LED effect

by shedboy71

The knightrider / larson / cylon effect

Schematic

knight rider

Code

[codesyntax lang=”cpp”]

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);
  }
}

[/codesyntax]

Share

You may also like