int inputPins[] = {2, 3, 4, 5}; // create an array of pins for switch inputs
int ledPins[] = {10, 11, 12, 13}; // create array of output pins for LEDs
void setup()
{
for (int index = 0; index < 4; index++)
{
pinMode(ledPins[index], OUTPUT); // declare LED as output
pinMode(inputPins[index], INPUT_PULLUP); // declare as input
}
}
void loop() {
for (int index = 0; index < 4; index++)
{
int val = digitalRead(inputPins[index]); // read input value
if (val == LOW) // check if the switch is pressed
{
digitalWrite(ledPins[index], HIGH); // LED on if switch is pressed
}
else
{
digitalWrite(ledPins[index], LOW); // turn LED off
}
}
}