int timer = 100; // The higher the number, the slower the timing.
int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; // an array of pin numbers to which LEDs are attached
int pinCount = 11; // the number of pins (i.e. the length of the array)
void setup()
{
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 13; thisPin++)
{
pinMode(thisPin, OUTPUT);
}
}
void loop()
{
// Speed up over 25 cycles, delays of 100 to 50
for (int timer = 120; timer > 20; timer -= 3)
{
oneCycle(timer);
}
// Slow down over 25 cycles, delays of 50 to 100
for (int timer = 20; timer < 120; timer += 3)
{
oneCycle(timer);
}
}
void oneCycle(int delayTime)
{
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 13; thisPin++)
{
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(delayTime);
// turn the pin off:
// digitalWrite(thisPin, LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = 12; thisPin >= 2; thisPin--)
{
// turn the pin on:
// digitalWrite(thisPin, HIGH);
// delay(delayTime);
// turn the pin off:
//digitalWrite(thisPin, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
}