#include <LiquidCrystal_I2C.h>
const int btnUp = 2;
const int btnDown = 3;
const int btnRight = 4;
const int btnLeft = 5;
int x = 0;
int y = 0;
bool tUp = false, tDown = false, tRight = false, tLeft = false;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
lcd.begin(20, 4);
pinMode(btnUp, INPUT_PULLUP);
pinMode(btnDown, INPUT_PULLUP);
pinMode(btnRight, INPUT_PULLUP);
pinMode(btnLeft, INPUT_PULLUP);
lcd.setCursor(x, y);
lcd.print("X");
}
void loop() {
if (digitalRead(btnUp) == LOW && !tUp && y > 0) {
y--;
tUp = true;
}
if (digitalRead(btnUp) == HIGH) {
tUp = false;
}
if (digitalRead(btnDown) == LOW && !tDown && y < 3) {
y++;
tDown = true;
}
if (digitalRead(btnDown) == HIGH) {
tDown = false;
}
if (digitalRead(btnRight) == LOW && !tRight && x < 15) {
x++;
tRight = true;
}
if (digitalRead(btnRight) == HIGH) {
tRight = false;
}
if (digitalRead(btnLeft) == LOW && !tLeft && x > 0) {
x--;
tLeft = true;
}
if (digitalRead(btnLeft) == HIGH) {
tLeft = false;
}
lcd.clear();
lcd.setCursor(x, y);
lcd.print("X");
}