int GREEN1 = 15;
int GREEN2 = 2;
int GREEN3 = 0;
int GREEN4 = 4;
int RED5 = 16;
int RED6 = 17;
int RED7 = 5;
int RED8 = 18;
int S1 = 14;
int S2 = 27;
int S3 = 26;
int S4 = 25;
bool switch1_on = false;
bool switch2_on = false;
bool switch3_on = false;
bool switch4_on = false;
void setup() {
pinMode(S1, INPUT);
pinMode(S2, INPUT);
pinMode(S3, INPUT);
pinMode(S4, INPUT);
pinMode(GREEN1, OUTPUT);
pinMode(GREEN2, OUTPUT);
pinMode(GREEN3, OUTPUT);
pinMode(GREEN4, OUTPUT);
pinMode(RED5, OUTPUT);
pinMode(RED6, OUTPUT);
pinMode(RED7, OUTPUT);
pinMode(RED8, OUTPUT);
}
void loop() {
if (digitalRead(S1)) {
if (!switch1_on) {
switch1_on = true;
switch2_on = false;
switch3_on = false;
switch4_on = false;
Switch1();
}
} else {
if (switch1_on) {
switch1_on = false;
ResetLEDs();
}
}
if (digitalRead(S2)) {
if (!switch2_on) {
switch1_on = false;
switch2_on = true;
switch3_on = false;
switch4_on = false;
Switch2();
}
} else {
if (switch2_on) {
switch2_on = false;
ResetLEDs();
}
}
if (digitalRead(S3)) {
if (!switch3_on) {
switch1_on = false;
switch2_on = false;
switch3_on = true;
switch4_on = false;
Switch3();
}
} else {
if (switch3_on) {
switch3_on = false;
ResetLEDs();
}
}
if (digitalRead(S4)) {
if (!switch4_on) {
switch1_on = false;
switch2_on = false;
switch3_on = false;
switch4_on = true;
Switch4();
}
} else {
if (switch4_on) {
switch4_on = false;
ResetLEDs();
}
}
// If none of the switches are on, reset LEDs
if (!switch1_on && !switch2_on && !switch3_on && !switch4_on) {
ResetLEDs();
}
}
void Switch1() {
while (switch1_on) {
LED(0,0,0,1,1,0,0,0, 300);
LED(0,0,1,0,0,1,0,0, 300);
LED(0,1,0,0,0,0,1,0, 300);
LED(1,0,0,0,0,0,0,1, 300);
if (!digitalRead(S1)) break; // Break out of loop if switch1 is no longer pressed
}
}
void Switch2() {
while (switch2_on) {
LED(1,0,0,0,0,0,0,1, 300);
LED(0,0,1,0,0,1,0,0, 300);
LED(0,0,0,1,1,0,0,0, 300);
LED(0,0,1,0,0,1,0,0, 300);
LED(0,1,0,0,0,0,1,0, 300);
LED(1,0,0,0,0,0,0,1, 300);
if (!digitalRead(S2)) break; // Break out of loop if switch2 is no longer pressed
}
}
void Switch3() {
while (switch3_on) {
LED(1,0,0,0,0,0,0,0, 300);
LED(0,1,0,0,0,0,0,0, 300);
LED(0,0,1,0,0,0,0,0, 300);
LED(0,0,0,1,0,0,0,0, 300);
LED(0,0,0,0,1,0,0,0, 300);
LED(0,0,0,0,0,1,0,0, 300);
LED(0,0,0,0,0,0,1,0, 300);
LED(0,0,0,0,0,0,0,1, 300);
LED(0,0,0,0,0,0,1,0, 300);
LED(0,0,0,0,0,1,0,0, 300);
LED(0,0,0,0,1,0,0,0, 300);
LED(0,0,0,1,0,0,0,0, 300);
LED(0,0,1,0,0,0,0,0, 300);
LED(0,1,0,0,0,0,0,0, 300);
LED(1,0,0,0,0,0,0,0, 300);
if (!digitalRead(S3)) break; // Break out of loop if switch3 is no longer pressed
}
}
void Switch4() {
while (switch4_on) {
LED(1,0,1,0,1,0,1,0, 300);
LED(0,1,0,1,0,1,0,1, 300);
if (!digitalRead(S4)) break; // Break out of loop if switch4 is no longer pressed
}
}
void LED(int a, int b, int c, int d, int e, int f, int g, int h, int t) {
digitalWrite(GREEN1, a);
digitalWrite(GREEN2, b);
digitalWrite(GREEN3, c);
digitalWrite(GREEN4, d);
digitalWrite(RED5, e);
digitalWrite(RED6, f);
digitalWrite(RED7, g);
digitalWrite(RED8, h);
delay(t);
}
void ResetLEDs() {
digitalWrite(GREEN1, LOW);
digitalWrite(GREEN2, LOW);
digitalWrite(GREEN3, LOW);
digitalWrite(GREEN4, LOW);
digitalWrite(RED5, LOW);
digitalWrite(RED6, LOW);
digitalWrite(RED7, LOW);
digitalWrite(RED8, LOW);
}