const int buttonPins[] = {2, 3, 4}; // Pins connected to the buttons
const int numOfButtons = sizeof(buttonPins) / sizeof(buttonPins[0]); // Number of buttons
void setup() {
Serial.begin(9600);
// Configure pins as inputs
for (int i = 0; i < numOfButtons; i++) {
int pinIndex = buttonPins[i];
pinMode(pinIndex, INPUT_PULLUP);
}
}
void loop() {
for (int i = 0; i < numOfButtons; i++) {
int buttonState = PIND & (1 << buttonPins[i]); // Masking out the specific pin state
if (buttonState == 0) {
switch (i) {
case 0:
Serial.println("Prižgan je rdeči gumb");
break;
case 1:
Serial.println("Button 2 is pressed");
break;
case 2:
Serial.println("Button 3 is pressed");
break;
}
delay(500);
}
}
}