#define horzPin A1
#define vertPin A0
#define selPin 2
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);
lcd.init();
lcd.backlight();
}
void moveCursor(int vertReading,int horzReading,int c,int r){
if(vertReading == 512 && horzReading == 0){
c++;
}
else if(vertReading == 512 && horzReading == 1023){
c--;
}
else if(vertReading == 1023 && horzReading == 512){
r++;
}
lcd.setCursor(c,r);
lcd.print("B");
}
void draw(int x,int y){
lcd.setCursor(x,y);
lcd.print("B");
}
void loop() {
// put your main code here, to run repeatedly:
bool selPressed = digitalRead(selPin) == LOW;
int vertReading = analogRead(vertPin);
int horzReading = analogRead(horzPin);
static int column = 0;
static int row = 0;
//if(selected[column][row] == 0){
// column ++;
// row ++;
// moveCursor(vertReading,horzReading,column,row);
// selected[column][row] = 1;
//
//}
if(vertReading == 512 && horzReading == 0){
if(selected[column][row] == false && column < 15){
column++;
draw(column,row);
//selected[column][row] = true;
}
}
else if(vertReading == 512 && horzReading == 1023 && column < 15){
if(selected[column][row] == false){
column ++;
draw(column,row);
//selected[column][row] = true;
}
}
else if(vertReading == 1023 && horzReading == 512 && row < 4){
if(selected[column][row] == false){
row++;
draw(column,row);
//selected[column][row] = true;
}
}
Serial.print(column);
Serial.print(" ");
Serial.println(row);
delay(1000);
}