#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
byte pBar[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
int rows = 2;
int columns = 16;
int buffer[2][16];
int row = 0;
int column = 0;
int symbol = 0;
const int pinX = A5;
const int pinY = A0;
const int pinBtn = 2;
int last_button = LOW;
int curr_button = LOW;
int debounce (int last)
{
int current = digitalRead(pinBtn);
if (last != current)
{
delay(5);
current = digitalRead(pinBtn);
}
return current;
}
void buttonPressed(int &last_button, int &curr_button, int &row)
{
curr_button = debounce(last_button);
if (last_button == LOW && curr_button == HIGH)
{
if (row == 0)
{
row = 1;
} else
{
row = 0;
}
}
last_button = curr_button;
}
void axisX(int x, int &column)
{
delay(10);
if (x > 512 && x <= 1023 && column > 0)
{
--column;
}
else if (x >= 0 && x < 512 && column < 15)
{
++column;
}
}
void axisY(int y, int &symbol)
{
delay(10);
if (y >= 0 && y < 512 && symbol > -1)
{
symbol -= 1;
}
else if (y > 512 && y <= 1023 && symbol < 25)
{
symbol += 1;
}
}
void setup()
{
lcd.begin(columns, rows);
lcd.createChar(0, pBar);
lcd.clear();
pinMode(pinX, INPUT);
pinMode(pinY, INPUT);
pinMode(pinBtn, INPUT);
digitalWrite(pinBtn, curr_button);
for (int i = 0; i < 16; ++i)
{
for (int j = 0; j < 2; ++j)
{
buffer[j][i] = -1;
}
}
}
void loop()
{
int x = analogRead(pinX);
int y = analogRead(pinY);
buttonPressed(last_button, curr_button, row);
axisX(x, column);
axisY(y, buffer[row][column]);
lcd.setCursor(column, row);
lcd.print("_");
delay(25);
for (int i = 0; i < 16; ++i)
{
for (int j = 0; j < 2; ++j)
{
lcd.setCursor(i, j);
if (buffer[j][i] == -1)
{
lcd.print(" ");
} else
{
char output = buffer[j][i] + 65;
lcd.print(output);
}
}
}
delay(25);
}