//Donna Ginting
#include <LiquidCrystal.h>
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the letters to display
const String letter1 = " 3 B"; // Letter for the first line
const String letter2 = " ELEKTROMEDIK"; // Letter for the second line
void setup() {
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Display the initial letters
displayLetters(letter1, letter2);
}
void loop() {
// Switch the positions of the letters 2 times
for (int i = 0; i < 2; i++) {
delay(1000); // Pause before switching
switchPositions();
delay(1000); // Pause before switching back
switchPositions();
}
// Stop the loop after switching 2 times
while (true); // Prevent further execution
}
// Function to display letters on the LCD
void displayLetters(String topLetter, String bottomLetter) {
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set cursor to the first line
lcd.print(topLetter); // Print the top letter
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print(bottomLetter); // Print the bottom letter
}
// Function to switch the positions of the letters
void switchPositions() {
static bool swapped = false; // Track whether letters are swapped
if (swapped) {
displayLetters(letter1, letter2); // Show original positions
} else {
displayLetters(letter2, letter1); // Show swapped positions
}
swapped = !swapped; // Toggle the swapped state
}