#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
randomSeed(analogRead(0)); // Initialize random seed
}
void loop() {
lcd.clear();
// Characters for the strings
char kelompok[] = "Kelompok 6";
char setya[] = "Setya";
char puji[] = "Pujiraharjo";
// Print "Kelompok 6" with randomized character positions
randomizeAndPrint(kelompok, 10, 0); // 10 is the length of "Kelompok 6"
delay(1000); // Pause after "Kelompok 6"
lcd.clear();
// Print "Setya" with randomized character positions
randomizeAndPrint(setya, 5, 0); // 5 is the length of "Setya"
delay(1000); // Pause after "Setya"
// Print "Pujiraharjo" with randomized character positions
randomizeAndPrint(puji, 11, 1); // 11 is the length of "Pujiraharjo"
delay(1000); // Pause after "Pujiraharjo"
lcd.clear();
}
// Function to randomize the display of characters in the string
void randomizeAndPrint(char* text, int length, int row) {
// Create an array to store the shuffled positions
int positions[length];
// Initialize the positions array with sequential numbers
for (int i = 0; i < length; i++) {
positions[i] = i;
}
// Shuffle the positions array using Fisher-Yates algorithm
for (int i = length - 1; i > 0; i--) {
int j = random(0, i + 1);
int temp = positions[i];
positions[i] = positions[j];
positions[j] = temp;
}
// Print the characters in random positions
for (int i = 0; i < length; i++) {
lcd.setCursor(positions[i], row); // Set the cursor to the random position
lcd.print(text[positions[i]]); // Print the character at that position
delay(random(200, 400)); // Random delay between printing each character
}
}