int timer = 200; // 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)
int LedPin[] = { 17, 14, 15, 16 }; // an array of pin numbers to which LEDs are attached
void setup()
{
// use a for loop to initialize each pin as an output:
for (int digitalpin = 2; digitalpin < 13; digitalpin++)
{
pinMode(digitalpin, OUTPUT);
}
// the array elements are numbered from 0 to (pinCount - 1).
for (int analogpins = 0; analogpins < 4; analogpins++)
{
pinMode(LedPin[analogpins], OUTPUT);
}
}
void loop()
{
for (int analogpins = 0; analogpins < 4; analogpins++)
{
// turn the pin on:
digitalWrite(LedPin[analogpins], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(LedPin[analogpins], LOW);
}
// Speed up over 25 cycles, delays of 100 to 50
for (int timer = 100; timer > 10; timer -= 2)
{
Cycle(timer);
}
// Slow down over 25 cycles, delays of 50 to 100
for (int timer = 10; timer < 100; timer += 2)
{
Cycle(timer);
}
}
void Cycle(int delayTime)
{
// loop from the lowest pin to the highest:
for (int digitalpin = 2; digitalpin < 13; digitalpin++)
{
// turn the pin on:
digitalWrite(digitalpin, 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);
for (int analogpins = 0; analogpins < 4; analogpins++)
{
// turn the pin on:
digitalWrite(LedPin[analogpins], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(LedPin[analogpins], LOW);
}
}