// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int coordinate_X = 0;
int coordinate_Y = 0;
const char* keys[] = {"safe", "money", "bar", "robot", "key", "terminal", "started", "fallout"};
void setup() {
lcd.begin(20, 4);
pinMode(30, INPUT_PULLUP); //Up button
pinMode(31, INPUT_PULLUP); //Left button
pinMode(32, INPUT_PULLUP); //Down button
pinMode(33, INPUT_PULLUP); //Right button
}
void loop() {
int up_button = digitalRead(30);
int left_button = digitalRead(31);
int down_button = digitalRead(32);
int right_button = digitalRead(33);
if (up_button == LOW) {
lcd.setCursor(0,0);
if (coordinate_Y > 0) {
coordinate_Y -= 1;
lcd.print(coordinate_X);
lcd.setCursor(0,1);
lcd.print(coordinate_Y);
}
}
if (left_button == LOW) {
lcd.setCursor(0,0);
if (coordinate_X > 0) {
coordinate_X -= 1;
lcd.print(coordinate_X);
lcd.setCursor(0,1);
lcd.print(coordinate_Y);
}
}
if (down_button == LOW) {
lcd.setCursor(0,0);
if (coordinate_Y < 4) {
coordinate_Y += 1;
lcd.print(coordinate_X);
lcd.setCursor(0,1);
lcd.print(coordinate_Y);
}
}
if (right_button == LOW) {
lcd.setCursor(0,0);
if (coordinate_X < 20) {
coordinate_X += 1;
lcd.print(coordinate_X);
lcd.setCursor(0,1);
lcd.print(coordinate_Y);
}
}
delay(1000);
lcd.clear();
}