#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String* label[4] = {"name", "num", "class", "grade"};
String val[4] = {"HARIHARAN", "9876543109", "1", "A+"};
uint8_t arrow[8] = {
0x00,
0x04,
0x06,
0x1F,
0x1F,
0x06,
0x04,
0x00
};
int index = 0;
int vert;
const int buttonPinInc = 2;
const int buttonPinDec = 3;
int oldValueInc = LOW;
int oldValueDec = LOW;
int home(int cursor_col, int cursor_row, int label_row1, int label_row2)
{
lcd.clear();
lcd.setCursor(cursor_col, cursor_row);
lcd.write(byte(0));
lcd.setCursor(1, 0);
lcd.print(label[label_row1]);
lcd.setCursor(1, 1);
lcd.print(label[label_row2]);
}
int setindex(int indx)
{
if (index == 0 && vert == 512)
{
// vert = analogRead(A0);
home(0, 0, index, index + 1);
// Serial.println(vert);
}
if (index == 1)
{
home(0, 1, index - 1, index);
// vert = analogRead(A0);
}
if (index == 2)
{
home(0, 0, index, index + 1);
// vert = analogRead(A0);
}
if (index == 3)
{
home(0, 1, index - 1, index);
// vert = analogRead(A0);
}
}
void setup() {
lcd.createChar(0, arrow);
lcd.begin(16, 2);
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
}
void loop() {
vert = analogRead(A0);
int horz = analogRead(A1);
Serial.println(vert);
if (index == 0 ) {
setindex(index);
do{
vert = analogRead(A0);
}while(vert == 512 && horz == 512);
}
if (vert == 1023 && index > 0)
{
index--;
setindex(index);
Serial.println(index);
}
if (vert == 0 && index < 4)
{
index++;
setindex(index);
Serial.println(index);
}
if (horz == 1023)
{
setindex(index);
}
if (horz == 0)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(val[index]);
}
delay(100);
}