Note that I used the press and release button when I press the button the LEDs are off and after I release the button LED behavior will start, and how to stop the infinite loop if I'll try to press and release another button and try to use another LED behaviour
const int buttonPin = 4;
const int buttonPin2 = 3;
const int buttonPin3 = 2;
const int ledPin[8] = {13,12,11,10,9,8,7,6};
int buttonState = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int lastButtonState = 0;
int lastButtonState2 = 0;
int lastButtonState3 = 0;
int d = 250;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
for (int i=0; i<8; i++){
pinMode(ledPin[i], OUTPUT);
}
}
void loop() {
//BLINKING LIGHTS
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == LOW) {
while(true){
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], HIGH);
}
delay(d);
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
delay(d);
}
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
}
else {
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
}
lastButtonState = buttonState;
}
//RING COUNTER
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 != lastButtonState2) {
if (buttonState2 == LOW) {
while(true) {
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], HIGH);
delay(d);
digitalWrite(ledPin[i], LOW);
delay(d);
}
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
}
}
else {
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
}
lastButtonState2 = buttonState2;
}
//JOHNSON COUNTER
buttonState3 = digitalRead(buttonPin3);
if (buttonState3 != lastButtonState3) {
if (buttonState3 == LOW) {
while(true) {
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], HIGH);
delay(500);
}
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
delay(500);
}
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
}
}
else {
for (int i=0; i<8; i++){
digitalWrite(ledPin[i], LOW);
}
}
lastButtonState3 = buttonState3;
}
}