int timer = 100; // The higher the number, the slower the timing.
int ledPins[] = {
2, 3,4,5,6,7,8,9 }; // an array of pin numbers to which LEDs are attached
int pinCount = 8; // the number of pins (i.e. the length of the array)
int buttonPin = A5;
int buttonPin2 = A4; // variable for reading the pushbutton status
// variables will change:
int buttonState=0; // variable for reading the dip switch status
int buttonState2=0; // variable for reading the dip switch status
void setup() {
int thisPin;
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(buttonPin,INPUT);
pinMode(buttonPin2,INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
// check if the dip switch is pressed.
// if it is, the buttonState is HIGH:
if(buttonState==HIGH && buttonState2==HIGH){
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}
}