change the number in a loop
const int buttonPin=2;
int flag = 1;
void setup() {
Serial.begin(9600);
for (int thisPin = 7; thisPin < 11; thisPin++) {
pinMode(thisPin, OUTPUT);
}
pinMode(buttonPin,INPUT);
}
void loop() {
if(digitalRead(buttonPin)==LOW){
flag = -flag;
}
if(flag==1){
Serial.println("Looping for 4 LED's");
for (int thisPin =7; thisPin < 11; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(200);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}else{
Serial.println("Looping for 3 LED's");
for (int thisPin =8; thisPin < 11; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(200);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
}