// Include the LiquidCrystal library for controlling LCD displays
#include <LiquidCrystal.h>
// Define LCD connections (replace with your actual pin connections)
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
// Variable to store the button press count
int counter = 0;
void setup() {
// Set all pins on port D as inputs with internal pull-up resistors
for (int i = 0; i < 8; i++) {
// Make pin i an input (DDRD &= ~(1<<i))
DDRD &= ~(1 << i);
// Enable pull-up resistor on pin i (PORTD |= 1<<i)
PORTD |= (1 << i);
}
// Initialize the LCD with 16 columns and 2 rows
lcd.begin(16, 2);
}
void loop() {
// Call function to read button states and update counter
zisti();
// Display message based on the button press count
if (counter > 4) {
// Set cursor to position (0, 0) on the LCD
lcd.setCursor(0, 0);
// Print "viac ako 4" (more than 4)
lcd.println("viac ako 4");
// Set cursor to position (0, 1) on the LCD
lcd.setCursor(0, 1);
// Print the counter value
lcd.println(counter);
} else if (counter == 4) {
// Set cursor to position (0, 0) on the LCD
lcd.setCursor(0, 0);
// Print "polka" (half)
lcd.println("polka");
// Set cursor to position (0, 1) on the LCD
lcd.setCursor(0, 1);
// Print the counter value
lcd.println(counter);
} else if (counter < 4) {
// Set cursor to position (0, 0) on the LCD
lcd.setCursor(0, 0);
// Print "menej ako 4" (less than 4)
lcd.println("menej ako 4");
// Set cursor to position (0, 1) on the LCD
lcd.setCursor(0, 1);
// Print the counter value
lcd.println(counter);
}
}
void zisti() {
// Reset the counter to 0
counter = 0;
for (int i = 0; i < 8; i++) {
// Check if the button connected to pin i is pressed (LOW reading)
if ((PIND & (1 << i)) == LOW) {
// Increment the counter if a button is pressed
counter++;
}
}
}