//making all the arrays and variables for the code
int buttonsCheck[] = {10, 9, 8, 7, 6, 5, 4, 3, 2};
int leds[] = {50, 48, 46, 44, 42, 40, 38, 36, 34};
const unsigned long dealyTime = 50;
unsigned long pastTime = 0;
int index = 50;
int helper = 0;
void setup() {
//making all the leds' pins to OUTPUT
for (int led : leds) {
pinMode(led, OUTPUT);
}
//making all the buttons' pins INPUT_PULLUP to ignore the resistor...
for (int checkerPin : buttonsCheck) {
pinMode(checkerPin, INPUT_PULLUP);
}
}
//making a function for shutting down all the leds
void noOther() {
for (int i : leds) {
digitalWrite(i, LOW);
}
}
void action() {
unsigned long currentTime = millis();
if (currentTime - pastTime >= dealyTime) {
//go through all the buttons, check them one by one if they pressed or not
//if yes, make that led's state HIGH that is the same indexed element of the leds array
for (int button : buttonsCheck) {
digitalWrite(index, !digitalRead(button));
/*if (digitalRead(button) == LOW) {
digitalWrite(index, HIGH);
}
if (digitalRead(button) == HIGH) {
digitalWrite(index, LOW);
}*/
index -= 2;
}
index = 50;
pastTime = currentTime;
}
}
void loop() {
action();
}