// LCD pins details: https://docs.wokwi.com/parts/wokwi-lcd1602
// Includes the library to allow the I2C communication from the micro to the LCD
#include <Wire.h> // https://www.arduino.cc/reference/en/language/functions/communication/wire/
// Includes the library used to manage the LCD through I2C (Inter-Integrated Circuit) communication protocol
#include <LiquidCrystal_I2C.h>
/*
https://www.arduino.cc/reference/en/libraries/liquidcrystal-i2c/
The LiquidCrystal_I2C.h Library configures the pin D22 of ESP32 as SDA (Serial DAta lne) to send the data to the LCD,
while pin D21 is configured as SCL (Serial CLock line) to sinchronize the serial data transmission between ESP32 & LCD.
https://youtu.be/CAvawEcxoPU
*/
LiquidCrystal_I2C I2C_LCD1(0x27, 16, 2); // set the LCD address as the device 0x27 (010 0111) with a 16 chars and 2 line display
LiquidCrystal_I2C I2C_LCD2(0x21, 16, 2); // set the LCD address as the device 0x28 (010 1000) with a 16 chars and 2 line display
LiquidCrystal_I2C I2C_LCD3(0x22, 16, 2); // set the LCD address as the device 0x10 (001 0000) with a 16 chars and 2 line display
#define botonder 15
#define botonizq 18
int i=0;
void setup()
{
attachInterrupt(botonder,contando,FALLING);
attachInterrupt(botonizq,contandos,FALLING);
// Initialize I2C communication with the LCD one, two and three
I2C_LCD1.init();
I2C_LCD2.init();
I2C_LCD3.init();
// Turn ON the backlight of the LCD one, two and three
I2C_LCD1.backlight();
I2C_LCD2.backlight();
I2C_LCD3.backlight();
}
void loop()
{
// Clear the LCD one, two and three of any previous message
I2C_LCD1.clear();
I2C_LCD2.clear();
I2C_LCD3.clear();
I2C_LCD1.setCursor(i,0);
I2C_LCD2.setCursor(i,0);
I2C_LCD3.setCursor(i,0);
// Display the first message in the first line of the LCD one, two and three
I2C_LCD1.print("Vamos");
I2C_LCD2.print("que onda");
I2C_LCD3.print("pon lo");
// Set the cursor position to column zero of line one of the LCD one, two and three
I2C_LCD1.setCursor(i,1);
I2C_LCD2.setCursor(i,1);
I2C_LCD3.setCursor(i,1);
// Display the second message starting in column zero of line one of the LCD
I2C_LCD1.print("por pan");
I2C_LCD2.print("cacheton");
I2C_LCD3.print("que sea");
// One second delay before displaying the message again
delay(1000);
}
void contando (){
if (i !=16){
i = i+1;
}
else if (i==16){
i=i;
}
}
void contandos (){
if (i !=0){
i = i-1;
}
else if (i==0){
i=i;
}
}