/*************************************************************
Download latest ERa library here:
https://github.com/eoh-jsc/era-lib/releases/latest
https://www.arduino.cc/reference/en/libraries/era
https://registry.platformio.org/libraries/eoh-ltd/ERa/installation
ERa website: https://e-ra.io
ERa blog: https://iotasia.org
ERa forum: https://forum.eoh.io
Follow us: https://www.fb.com/EoHPlatform
*************************************************************/
// Enable debug console
// Set CORE_DEBUG_LEVEL = 3 first
// #define ERA_DEBUG
// You should get Auth Token in the ERa App or ERa Dashboard
#define ERA_AUTH_TOKEN "46d03570-9b4f-4012-b852-b53674b56760"
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <ERaSimpleEsp32.hpp>
#include <ERa/ERaTimer.hpp>
#include <Wire.h>
#include <Button.h>
int lcdColumns = 16;
int lcdRows = 2;
Button buttonn = 5;
int cout=0;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
const char ssid[] = "Wokwi-GUEST";
const char pass[] = "";
ERaTimer timer;
/* This function print uptime every second */
void timerEvent() {
ERA_LOG("Timer", "Uptime: %d", ERaMillis() / 1000L);
}
void LCD(){
if(buttonn.pressed()){
cout++;
if(cout==1){
while(true){
lcd.print("Tran Thai Hoc");
delay(1000);
// clears the display to print new message
lcd.clear();
// set cursor to first column, second row
lcd.setCursor(0,1);
lcd.print("20CT111");
delay(1000);
lcd.clear();
if (buttonn.pressed()) { // Nếu nút được nhấn lần thứ hai
cout = 0; // Đặt lại biến đếm
lcd.clear(); // Xóa màn hình LCD
break; // Thoát khỏi vòng lặp
}
}
}
}
}
void setup() {
/* Setup debug console */
Serial.begin(115200);
/* Enable get config after reset */
ERa.askConfigWhenRestart();
ERa.begin(ssid, pass);
/* Setup timer called function every second */
timer.setInterval(1000L, timerEvent);
lcd.init();
// turn on LCD backlight
lcd.backlight();
lcd.setCursor(0, 0);
buttonn.begin();
}
void loop() {
ERa.run();
timer.run();
LCD();
delay(10);
}