#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
enum directions
{
LEFT = 0,
RIGHT = 1
};
char LCDline[] = "0123456789ABCDEF";
const char *myStrings[] = {"1. Short Length ",
"<<< Small Curl ",
"2. Short Length ",
"<<< Medium Curl ",
"3. Short Length ",
"<<< Large Curl ",
"4.Regular Length",
" Small Curl >>>",
"5.Regular Length",
" Meduim Curl >>>",
"6.Regular Length",
" Large Curl >>>",
" WRONG PROGRAM ",
"!!! SELECTED !!!"};
int oldSelected = 0;
int selected = 1;
unsigned int scroll = 0;
long oldMillis;
directions direction = RIGHT;
void setup()
{
lcd.init(); // Initialize the LCD I2C display
lcd.backlight();
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
oldMillis = millis();
direction = LEFT;
}
void copyLine(const char *origin, int offset)
{
for (int i = 0; i < 16; i++)
LCDline[i] = origin[offset + i];
}
void LCDprint(const char *line, const int x, const int y)
{
lcd.setCursor(x, y); // move cursor to (3, 0)
lcd.print(line);
}
void loop()
{
bool Bit0 = digitalRead(A0); // read A output from sewitch
bool Bit1 = digitalRead(A1); // read B output from sewitch
bool Bit2 = digitalRead(A2); // read C output from sewitch
bool Bit3 = digitalRead(A3); // read D output from sewitch
selected = Bit0 + (Bit1 << 1) + (Bit2 << 2) + (Bit3 << 3); // convert bits to HEX
if (selected < 1 || selected > 6)
selected = 7;
if (selected != oldSelected)
{
oldSelected = selected;
oldMillis = millis();
scroll = 0;
direction = LEFT;
}
copyLine(myStrings[selected * 2 - 2], scroll);
LCDprint(LCDline, 0, 0);
// lcd.setCursor(0, 0); // move cursor to (3, 0)
// lcd.print(LCDline);
LCDprint(myStrings[selected * 2 - 1], 0, 1);
// lcd.setCursor(0, 1); // move cursor to (0, 1)
// lcd.print(myStrings[selected * 2 - 1]); // print message at (0, 1)
if (millis() - oldMillis > 333)
{
oldMillis = millis();
if (direction == LEFT)
{
if (scroll < strlen(myStrings[selected * 2 - 2]) - 16)
{
scroll++;
}
else
direction = RIGHT;
}
else
{
if (scroll > 0)
{
scroll--;
}
else
direction = LEFT;
}
}
delay(100);
}