LED Chasing Lights Progamming

Try this, it fades a group of LEDs on and off. After that do a bit of experimenting. :slight_smile:

const int numberOfLEDs = 14;

volatile byte wantedPins [numberOfLEDs] =  { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 };   // which pin to pulse on and off

const byte PWMiterations = 40;
byte PWMdutyCycle;   // <-- should be less than PWMiterations

volatile byte pwmCount;

ISR(TIMER1_COMPA_vect)
{
byte i;

  if (pwmCount > PWMdutyCycle)
    {
    // turn all off
    for (i = 0; i < numberOfLEDs; i++)
      digitalWrite(i, LOW);      
    }
  else
    {
    // turn wanted ones on
    for (i = 0; i < numberOfLEDs; i++)
      if (wantedPins [i])
        digitalWrite(i, HIGH);      
    }
    
   
 if (++pwmCount >= PWMiterations)
   pwmCount = 0;
}

void setup() 
  {                
  for (byte i = 0; i < numberOfLEDs; i++)  
    pinMode(i, OUTPUT);
    
  // set up Timer 1
  TCCR1A = 0;          // normal operation
  TCNT1 = 0;           // make sure we start at zero
  TCCR1B = _BV(WGM12) | _BV(CS10) | _BV (CS12);   // CTC, scale to clock / 1024
  OCR1A =  5;       // compare A register value (1000 * clock speed / 1024)
  TIMSK1 = _BV (OCIE1A);             // interrupt on Compare A Match
    
  }  // end of setup

 
void loop() 
  {
  for (PWMdutyCycle = 0; PWMdutyCycle < PWMiterations; PWMdutyCycle++)
    delay (100);

  for (PWMdutyCycle = PWMiterations; PWMdutyCycle > 0; PWMdutyCycle--)
    delay (100);
    
  } // end of loop