const int switchPin1 = A0; // Pin for the first red momentary contact switch
const int switchPin2 = A1; // Pin for the second yellow momentary contact switch
const int switchPin3 = A2; // Pin for the third switch
const int switchPin4 = A3; // Pin for the fourth switch
const int switchPin5 = A4; // Pin for the fifth switch
const int switchPin6 = A5; // Pin for the sixth switch
const int switchPin7 = 13; // Pin for the seventh switch
const int switchPin8 = 12; // Pin for the eighth switch
const int switchPin9 = 11; // Pin for the ninth switch
const int ledPin1 = 2; // Pin for the first LED
const int ledPin2 = 3; // Pin for the second LED
const int ledPin3 = 4; // Pin for the third LED
const int ledPin4 = 5; // Pin for the fourth LED
const int ledPin5 = 6; // Pin for the fifth LED
const int ledPin6 = 7; // Pin for the sixth LED
const int ledPin7 = 8; // Pin for the seventh LED
const int ledPin8 = 9; // Pin for the eighth LED
const int ledPin9 = 10; // Pin for the ninth LED
bool switchState1 = false; // Current state of the first switch
bool switchState2 = false; // Current state of the second switch
bool switchState3 = false; // Current state of the third switch
bool switchState4 = false; // Current state of the fourth switch
bool switchState5 = false; // Current state of the fifth switch
bool switchState6 = false; // Current state of the sixth switch
bool switchState7 = false; // Current state of the seventh switch
bool switchState8 = false; // Current state of the eighth switch
bool switchState9 = false; // Current state of the ninth switch
bool ledState1 = false; // Current state of the first LED
bool ledState2 = false; // Current state of the second LED
bool ledState3 = false; // Current state of the third LED
bool ledState4 = false; // Current state of the fourth LED
bool ledState5 = false; // Current state of the fifth LED
bool ledState6 = false; // Current state of the sixth LED
bool ledState7 = false; // Current state of the seventh LED
bool ledState8 = false; // Current state of the eighth LED
bool ledState9 = false; // Current state of the ninth LED
bool previousSwitchState1 = false; // Previous state of the first switch
bool previousSwitchState2 = false; // Previous state of the second switch
bool previousSwitchState3 = false; // Previous state of the third switch
bool previousSwitchState4 = false; // Previous state of the fourth switch
bool previousSwitchState5 = false; // Previous state of the fifth switch
bool previousSwitchState6 = false; // Previous state of the sixth switch
bool previousSwitchState7 = false; // Previous state of the seventh switch
bool previousSwitchState8 = false; // Previous state of the eighth switch
bool previousSwitchState9 = false; // Previous state of the ninth switch
void setup() {
pinMode(switchPin1, INPUT_PULLUP); // Set the first switch pin as input with internal pull-up resistor
pinMode(switchPin2, INPUT_PULLUP); // Set the second switch pin as input with internal pull-up resistor
pinMode(switchPin3, INPUT_PULLUP); // Set the third switch pin as input with internal pull-up resistor
pinMode(switchPin4, INPUT_PULLUP); // Set the fourth switch pin as input with internal pull-up resistor
pinMode(switchPin5, INPUT_PULLUP); // Set the fifth switch pin as input with internal pull-up resistor
pinMode(switchPin6, INPUT_PULLUP); // Set the sixth switch pin as input with internal pull-up resistor
pinMode(switchPin7, INPUT_PULLUP); // Set the seventh switch pin as input with internal pull-up resistor
pinMode(switchPin8, INPUT_PULLUP); // Set the eighth switch pin as input with internal pull-up resistor
pinMode(switchPin9, INPUT_PULLUP); // Set the ninth switch pin as input with internal pull-up resistor
pinMode(ledPin1, OUTPUT); // Set the first LED pin as output
pinMode(ledPin2, OUTPUT); // Set the second LED pin as output
pinMode(ledPin3, OUTPUT); // Set the third LED pin as output
pinMode(ledPin4, OUTPUT); // Set the fourth LED pin as output
pinMode(ledPin5, OUTPUT); // Set the fifth LED pin as output
pinMode(ledPin6, OUTPUT); // Set the sixth LED pin as output
pinMode(ledPin7, OUTPUT); // Set the seventh LED pin as output
pinMode(ledPin8, OUTPUT); // Set the eighth LED pin as output
pinMode(ledPin9, OUTPUT); // Set the ninth LED pin as output
}
void loop() {
switchState1 = digitalRead(switchPin1); // Read the state of the first switch
switchState2 = digitalRead(switchPin2); // Read the state of the second switch
switchState3 = digitalRead(switchPin3); // Read the state of the third switch
switchState4 = digitalRead(switchPin4); // Read the state of the fourth switch
switchState5 = digitalRead(switchPin5); // Read the state of the fifth switch
switchState6 = digitalRead(switchPin6); // Read the state of the sixth switch
switchState7 = digitalRead(switchPin7); // Read the state of the seventh switch
switchState8 = digitalRead(switchPin8); // Read the state of the eighth switch
switchState9 = digitalRead(switchPin9); // Read the state of the ninth switch
if (switchState1 != previousSwitchState1) {
if (switchState1 == LOW) { // If the first switch is pressed
ledState1 = !ledState1; // Toggle the first LED state
digitalWrite(ledPin1, ledState1); // Set the first LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState2 != previousSwitchState2) {
if (switchState2 == LOW) { // If the second switch is pressed
ledState2 = !ledState2; // Toggle the second LED state
digitalWrite(ledPin2, ledState2); // Set the second LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState3 != previousSwitchState3) {
if (switchState3 == LOW) { // If the third switch is pressed
ledState3 = !ledState3; // Toggle the third LED state
digitalWrite(ledPin3, ledState3); // Set the third LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState4 != previousSwitchState4) {
if (switchState4 == LOW) { // If the fourth switch is pressed
ledState4 = !ledState4; // Toggle the fourth LED state
digitalWrite(ledPin4, ledState4); // Set the fourth LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState5 != previousSwitchState5) {
if (switchState5 == LOW) { // If the fifth switch is pressed
ledState5 = !ledState5; // Toggle the fifth LED state
digitalWrite(ledPin5, ledState5); // Set the fifth LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState6 != previousSwitchState6) {
if (switchState6 == LOW) { // If the sixth switch is pressed
ledState6 = !ledState6; // Toggle the sixth LED state
digitalWrite(ledPin6, ledState6); // Set the sixth LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState7 != previousSwitchState7) {
if (switchState7 == LOW) { // If the seeventh switch is pressed
ledState7 = !ledState7; // Toggle the seventh LED state
digitalWrite(ledPin7, ledState7); // Set the seventh LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState8 != previousSwitchState8) {
if (switchState8 == LOW) { // If the eight switch is pressed
ledState8 = !ledState8; // Toggle the eight LED state
digitalWrite(ledPin8, ledState8); // Set the eigth LED pin to the new state
}
delay(50); // Delay for debouncing
}
if (switchState9 != previousSwitchState9) {
if (switchState9 == LOW) { // If the ninth switch is pressed
ledState9 = !ledState9; // Toggle the ninth LED state
digitalWrite(ledPin9, ledState9); // Set the ninth LED pin to the new state
}
delay(50); // Delay for debouncing
}
previousSwitchState1 = switchState1;
previousSwitchState2 = switchState2;
previousSwitchState3 = switchState3;
previousSwitchState4 = switchState4;
previousSwitchState5 = switchState5;
previousSwitchState6 = switchState6;
previousSwitchState7 = switchState7;
previousSwitchState8 = switchState8;
previousSwitchState9 = switchState9;
}