Programming Examples

Write a program to display button press count on an LCD.


O level July 2025 practical Exam question

Write a program to display button press count on an LCD.

Solution

#include <LiquidCrystal.h>

// RS, E, D4, D5, D6, D7 pins connected to Arduino
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define BUTTON_PIN 7

int count = 0;
int lastButtonState = HIGH;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  lcd.begin(16, 2);
  lcd.print("Button Count:");
}

void loop() {
  int buttonState = digitalRead(BUTTON_PIN);

  // Detect button press (HIGH to LOW transition)
  if (buttonState == LOW && lastButtonState == HIGH) {
    count++;
    lcd.setCursor(0, 1);
    lcd.print("Count: ");
    lcd.print(count);
    delay(200); // Simple debounce
  }

  lastButtonState = buttonState;
}
Output


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad