#include <LiquidCrystal_I2C.h>
#define I2C_ADD 0X27
#define COL 16
#define ROW 2
#define VERT 26
#define HORZ 27
#define SEL 14
LiquidCrystal_I2C lcd(I2C_ADD,COL,ROW);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.init();
lcd.backlight();
pinMode(VERT,INPUT);
pinMode(HORZ,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int vert = map(analogRead(VERT),0,4095,-100,100);
int horz = map(analogRead(HORZ),0,4095,-100,100);
lcd.setCursor(0,0);
lcd.print("MOVEMENT :");
lcd.setCursor(0,1);
if(vert==100 && horz==100){
Serial.println("TOP-LEFT");
lcd.print("TOP-LEFT ");
}else if(vert==100 && horz==0){
Serial.println("TOP");
lcd.print("TOP ");
}else if(vert==100 && horz == -100){
Serial.println("TOP-RIGHT");
lcd.print("TOP-RIGHT ");
}else if(vert==0 && horz == 100){
Serial.println("LEFT");
lcd.print("LEFT ");
}else if(vert==0 && horz == -100){
Serial.println("RIGHT");
lcd.print("RIGHT ");
}else if(vert== -100 && horz == 100){
Serial.println("BOTTOM-LEFT");
lcd.print("BOTTOM-LEFT ");
}else if(vert == -100 && horz == 0){
Serial.println("BOTTOM");
lcd.print("BOTTOM ");
}else if(vert == -100 && horz == -100){
Serial.println("BOTTOM-RIGHT");
lcd.print("BOTTOM-RIGHT ");
}else{
Serial.println("CENTER");
lcd.print("CENTER ");
}
Serial.println(String(horz)+" "+String(vert));
delay(10); // this speeds up the simulation
}