if (digitalRead(x1) == HIGH && digitalRead(y1) == HIGH) {
EEPROM.write(1, true);}
if (digitalRead(x2) == HIGH && digitalRead(y1) == HIGH) {
EEPROM.write(2, true);}
if (digitalRead(x3) == HIGH && digitalRead(y1) == HIGH) {
EEPROM.write(3, true);}
if (digitalRead(x4) == HIGH && digitalRead(y1) == HIGH) {
EEPROM.write(4, true);}
if (digitalRead(x5) == HIGH && digitalRead(y1) == HIGH) {
EEPROM.write(5, true);}
i am making 5x5x5 led cube, and i want to read what coordinates are pressed to save the led that needs to light up, this is done layer by layer. How can i simplify this code (with a loop)?
First read all the buttons and save their values to variables. if you put the button pin numbers and the button states in arrays you can do it like this
for (byte n = 0; n < numButtons; n++) {
buttonState[n] = digitalRead(buttonPin[n]);
}
and then you can probably test the combinations of the saved values with a similar FOR loop.