#include <LCD_I2C.h>
LCD_I2C lcd(0x27,16,2);
const int button1 = 8;
const int button2 = 2;
const int button3 = 12;
const int button4 = 13;
int button1State = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;
int lastButton1 = 0;
int lastButton2 = 0;
int lastButton3 = 0;
int lastButton4 = 0;
int x = 0;
int y = 0;
void setup() {
lcd.begin();
lcd.backlight();
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
lcd.setCursor(x, y);
lcd.print("x");
}
void loop() {
button1State = digitalRead(button1);
if (button1State == LOW && lastButton1 == HIGH) {
if (x < 15) x++;
lcd.clear();
lcd.setCursor(x, y);
lcd.print("x");
delay(300);
}
lastButton1 = button1State;
button2State = digitalRead(button2);
if (button2State == LOW && lastButton2 == HIGH) {
if (y < 1) y++;
lcd.clear();
lcd.setCursor(x, y);
lcd.print("x");
delay(300);
}
lastButton2 = button2State;
button3State = digitalRead(button3);
if (button3State == LOW && lastButton3 == HIGH) {
if (y > 0) y--;
lcd.clear();
lcd.setCursor(x, y);
lcd.print("x");
delay(300);
}
lastButton3 = button3State;
button4State = digitalRead(button4);
if (button4State == LOW && lastButton4 == HIGH) {
if (x > 0) x--;
lcd.clear();
lcd.setCursor(x, y);
lcd.print("x");
delay(300);
}
lastButton4 = button4State;
}