#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SOLAR_PIN 34
#define BATTERY_PIN 35
#define WATT_PIN 32
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
// Read ADC values and convert to voltage/wattage
float solarVoltage = (analogRead(SOLAR_PIN) / 4095.0) * 3.3 * 6.0;
float batteryVoltage = (analogRead(BATTERY_PIN) / 4095.0) * 3.3 * 6.0;
float wattage = (analogRead(WATT_PIN) / 4095.0) * 3.3 * 60.0;
// Prepare formatted strings
String solarStr = solarVoltage >= 10.0 ? String(solarVoltage, 1) + "V " : " " + String(solarVoltage, 1) + "V ";
String batteryStr = batteryVoltage >= 10.0 ? String(batteryVoltage, 1) + "V " : " " + String(batteryVoltage, 1) + "V ";
String wattStr = wattage >= 100 ? String((int)wattage) + "W" : " " + String((int)wattage) + "W";
// Print formatted strings to the LCD
lcd.setCursor(0, 0);
lcd.print(solarStr);
lcd.setCursor(0, 1);
lcd.print(batteryStr);
lcd.setCursor(12, 1);
lcd.print(wattStr);
delay(350);
}