#include <Arduino.h> // somente para o PlatformIO
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
// endereço do device (LCD I2C) no barramento I2C, 20 colunas, 4 linhas
#define LED 5
#define POT1 34
#define POT2 35
// Variável
// Simulação de sensores de tensão e corrente
int valorPOT1_V; // analogRead ----> 0 a 4095 (ADC de 12 bits)
int valorPOT2_I;
float tensao; // 0 a 240V
float corrente; // 0 a 20A
void piscaLED(){
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
void leituraSensores(){
valorPOT1_V = analogRead(POT1);
valorPOT2_I = analogRead(POT2);
tensao = (map(valorPOT1_V, 0, 4095, 0, 2400) / 10.0); // tensão 0.00 a 240.0
corrente = (map(valorPOT2_I, 0, 4095, 0, 200) / 10.0); // corrente 0.00 a 20.0A
lcd.setCursor(0, 0);
lcd.print("Tensao: ");
lcd.print(tensao); // 000.0
lcd.print(" V ");
lcd.setCursor(0, 1);
lcd.print("Corrente: ");
lcd.print(corrente); // 00.0
lcd.print(" A ");
}
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
// Inicializa LCD
lcd.init();
// ativa a luz de fundo (backlight)
lcd.backlight();
lcd.setCursor(0, 0); // coluna, linha
lcd.print(" Medidor de energia ");
lcd.setCursor(0, 1);
lcd.print(" 1EMA - CTFE ");
lcd.setCursor(0, 2);
lcd.print(" NEXT - 2025 ");
lcd.setCursor(0, 3);
lcd.print(" 10/10/2025 ");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Sistema Iniciado...");
}
void loop() {
leituraSensores();
}