#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
uint8_t menuOptions = 3;
int8_t topOption = -1;
int8_t cursorPos = 0;
void DrawMenu(uint8_t topOpt){
if(topOpt!=topOption){
topOption = topOpt;
for (uint8_t i = 0;i<4;i++){
DrawOption(i,topOption);
}
}
DrawCursor(cursorPos);
}
void DrawOption(uint8_t pos,uint8_t optionID){
lcd.setCursor(1, pos);
lcd.print("Option ");
lcd.print(optionID);
}
void DrawCursor(uint8_t pos){
if (cursorPos!=pos){
if (cursorPos>-1){
lcd.setCursor(0, cursorPos);
lcd.print(' ');
}
if (pos<4){
cursorPos = pos;
lcd.setCursor(0, pos);
lcd.print('>');
}else{
cursorPos = -1;
}
}
}
int8_t pos = -1;
void setup()
{
Serial.begin(115200);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("Hello, world!");
lcd.setCursor(1, 1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(1, 2);
lcd.print("Arduino");
moveCursor(1);
DrawMenu(0);
}
void moveCursor(int8_t p) {
// put your main code here, to run repeatedly:
if (pos>-1){
lcd.setCursor(0, pos);
lcd.print(' ');
}
if (p>-1 && p<4){
pos=p;
lcd.setCursor(0, pos);
lcd.print('>');
}
}
char cc;
void readSerial() {
if (Serial.available() > 0) {
char c = Serial.read();
if (c != '\n') {
if (Serial.read() == '\n') {
cc = c;
// keypad.triggerKeyPress(c);
}
}
while (Serial.available() > 0) Serial.read();
}
//
}
void onInput(char c) {
if (c != 0) {
Serial.print(F("Trigger Key '"));
Serial.print(c);
Serial.println(F("'"));
// keypad.triggerKeyPress(c);
}
cc = 0;
}
void loop() {
// put your main code here, to run repeatedly:
readSerial();
delay(100);
}