/*
LCD I²C HELLO WORLD
MADE BY BRAYLEN HAMMOND
YOU MAY USE THE CODE AND DIAGRAM TO HELP YOU WITH YOUR LCD.
THIS CODE DOESNT APPLY TO THE NORMAL LCD, IT ONLY
APPLIES TO THE I2C LCD. YOU CAN DO THIS ON WOKWI OR
ON YOUR ACTUAL ARDUINO. THIS PROJECT IS ONLY
TESTED THE ARDUINO UNO, YOU CAN TRY ON OTHER
ARDUINOES TO SEE IF IT WORKS.
GO TO MY YOUTUBE CHANNEL FOR MORE HELP WITH CODING AN ARDUINO. Please Subscribe, it's free and it'll help out a ton.
https://www.youtube.com/channel/UCccMHKRai1dwgxwFg-w8hZA
Have fun, be creative and enjoy the help I do for you
*/
// Add the Liquid Crystal I2C library
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Potentiometer PIN A1
int Keyboard = A7;
// Variables capturing current and newly calculated position on the letter board (9x3 - 27 positions)
int New_X = 0;
int Old_X = 0;
int New_Y = 0;
int Old_Y = 0;
// Variable capturing output from Keyboard pin (Values 0 - 1023)
int Key_read = 0;
int Prev_Key_read = 1023;
boolean Key_pressed = false;
// String variable holding the text to transmit
String To_Transmit = "";
// Length of the text to transmit
int To_Transmit_Length = 0;
// Used for displaying Letter board
char Letters[3][9] = {"ABCDEFGHI",
"JKLMNOPQR",
"STUVWXYZ_"};
void setup() {
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Display the initial "OK" indicator
lcd.setCursor(14, 0);
lcd.print("OK");
// Display Letter Board (3 rows, 9 characters in each row)
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 9; i++) {
lcd.setCursor(i, j + 1);
lcd.print(Letters[j][i]);
}
}
// Highlight character 'A' by placing a cursor at the first position
lcd.setCursor(0, 1);
lcd.blink(); // This will make the cursor blink on the selected character
}
void Highlight_letter(int X, int X_Old, int Y, int Y_Old) {
// Unhighlight the old position
lcd.noBlink();
lcd.setCursor(X_Old, Y_Old + 1);
// Highlight the new position
lcd.setCursor(X, Y + 1);
lcd.blink();
}
void loop() {
Key_read = analogRead(Keyboard);
if (Prev_Key_read > 1000 && Key_read < 1000) {
Key_pressed = true;
if (Key_read < 10 && Old_X > 0) New_X = Old_X - 1;
if (Key_read > 160 && Key_read < 170 && Old_X < 8) New_X = Old_X + 1;
if (Key_read > 25 && Key_read < 35 && Old_Y > 0) New_Y = Old_Y - 1;
if (Key_read > 80 && Key_read < 90 && Old_Y < 2) New_Y = Old_Y + 1;
if (Key_read > 350 && Key_read < 360) {
if (New_Y != -1) {
To_Transmit = To_Transmit + Letters[New_Y][New_X];
To_Transmit_Length++;
lcd.setCursor(0, 0);
lcd.print(To_Transmit);
} else {
lcd.clear();
lcd.print("Sending...");
delay(2000); // Simulate sending process
lcd.clear();
}
}
if ((Old_X != New_X || Old_Y != New_Y) && Old_Y != -1) {
Highlight_letter(New_X, Old_X, New_Y, Old_Y);
Old_X = New_X;
Old_Y = New_Y;
}
}
Prev_Key_read = Key_read;
}