#define horzPin A0
#define vertPin A1
#define selPin 2
#define selPin_2 3
#define vertPin_2 A2
#define horzPin_2 A3
#define ledPin 12
int column = 0;
int row = 0;
bool selected[11][11];
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(horzPin, INPUT);
pinMode(vertPin,INPUT);
pinMode(selPin, INPUT_PULLUP);
pinMode(ledPin,INPUT);
lcd.init();
lcd.backlight();
}
/*
direction horz vert
TOP 512 1023
LEFT 1023 512
RIGHT 0 512
BOTTOM 512 0
*/
void draw(int horzRead,int vertRead,int x,int y){
if(horzRead == 512 && vertRead == 1023){
lcd.setCursor(0,0);
lcd.print("TOP");
}
else if(horzRead == 1023 && vertRead == 512){
lcd.setCursor(0,1);
lcd.print("LEFT");
}
else if(horzRead == 0 && vertRead == 512){
lcd.setCursor(0,2);
lcd.print("RIGHT");
}
else if(horzRead == 512 && vertRead == 0){
lcd.setCursor(0,3);
lcd.print("BOTTOM");
}
}
void moveCursor(int horzRead,int vertRead,int col,int rw){
lcd.setCursor(col,rw);
selected[col][rw] = 1;
lcd.print("B");
}
void loop() {
// put your main code here, to run repeatedly:
int vertReading = analogRead(vertPin);
int horzReading = analogRead(horzPin);
int vertReading_2 = analogRead(vertPin_2);
int horzReading_2 = analogRead(horzPin_2);
bool selPressed = digitalRead(selPin) == LOW;
bool selPressed_2 = digitalRead(selPin_2) == LOW;
moveCursor(horzReading,vertReading,column,row);
if(horzReading == 512 && vertReading == 0){
if(selected[column][row] == 0){
row ++;
}
}
//draw(vertReading_2,horzReading_2,analogRead(ledPin));
}