// simple project using Arduino UNO and 16x2 character display to display smooth gauge,
// created by upir, 2022
// youtube channel: https://www.youtube.com/upir_upir
// FULL TUTORIAL: https://youtu.be/ZzIGHiHObYw
// GAUGE IN 11 MINUTES TUTORIAL: https://youtu.be/upE17NHrdPc
// Links related to this project:
// Arduino UNO - https://s.click.aliexpress.com/e/_AXDw1h
// Arduino breadboard prototyping shield - https://s.click.aliexpress.com/e/_ApbCwx
// 16x2 displays with IIC - https://s.click.aliexpress.com/e/_9Hl3JV
// 16x2 display with RGB backlight - https://s.click.aliexpress.com/e/_9wgpeb
// original sketch from YWROBOT - https://wokwi.com/arduino/libraries/LiquidCrystal_I2C/HelloWorld
// character creator - https://tusindfryd.github.io/screenduino/
// another character creator - https://maxpromer.github.io/LCD-Character-Creator/
// sprintf explanation - https://www.programmingelectronics.com/sprintf-arduino/
// custom characters simplest project - https://wokwi.com/projects/294395602645549578
// Arduino I2C scanner - https://playground.arduino.cc/Main/I2cScanner/
// 16x2 available characters - https://docs.wokwi.com/parts/wokwi-lcd1602#font
// Bitwise Operators in GIFs - https://blog.wokwi.com/bitwise-operators-in-gifs/
// Bitwise operators Arduino documentation - https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitshiftleft/
#include <LiquidCrystal_I2C.h> // if you don´t have I2C version of the display, use LiquidCrystal.h library instead
LiquidCrystal_I2C lcd(0x27, 16, 2);
// set the LCD address to 0x27 for a 16 chars and 2 line display
//LiquidCrystal_I2C lcd(0x3f,16,2); // set the LCD address to 0x3f for a 16 chars and 2 line display
// if you don´t know the I2C address of the display, use I2C scanner first (https://playground.arduino.cc/Main/I2cScanner/)
int screenWidth = 16;
int screenHeight = 2;
int stringStart = 0;
int stringEnd = 0;
int scrollCursor = screenWidth;
String line1 = "Tecle * ";
String line2 = "Sistema de controle de acesso."; //scroll this line
void setup()
{
lcd.init(); // initialize the 16x2 lcd module
lcd.backlight(); // enable backlight for the LCD module
lcd.begin(screenWidth, screenHeight);
}
void loop()
{
// print the string on the display
lcd.setCursor (0, 1); // Seting the cursor on first row
lcd.print (line1);
lcd.setCursor (scrollCursor, 0); // Seting the cursor on first row and (scrolling from left to right)
lcd.print(line2.substring(stringStart, stringEnd)); // To print line1 first character "T"
//Serial.println (line2.substring(stringStart, stringEnd));
delay (250);
//lcd.clear(); // clear message
lcd.setCursor(0, 0);
lcd.print(" ");
if (stringStart == 0 && scrollCursor > 0)
{
scrollCursor --; // moving cursor from 16 to 0
stringEnd ++;
} //character T, H, I, S ...
// it wil print out character from 0 to 15 (entire length of the screen)
else if (stringStart == stringEnd)
{
stringStart = stringEnd = 0; // start oll over again
scrollCursor = screenWidth;
}
else if (stringEnd == line2.length() and scrollCursor == 0)
{
stringStart ++;
} // if reaches to end character
else // it will print out character from (1 to 16) to end character
{
stringStart ++;
stringEnd ++;
}
}