#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int voltagePin = A0;
const int currentPin = A1;
const int buttonPin = 2;
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address and dimensions
int displayMode = 0; // 0: voltage, 1: current, 2: power
void setup() {
lcd.init();
lcd.backlight();
pinMode(buttonPin, INPUT);
// Welcome Screen
lcd.setCursor(0, 0);
lcd.print("Pakk Tech");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("MPPT Max 60V 60A");
delay(1500);
lcd.clear();
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// Toggle display mode
displayMode = (displayMode + 1) % 3;
delay(50); // debounce
lcd.clear();
}
// Display selected mode
if (displayMode == 0) {
// Display solar voltage
int voltageValue = analogRead(voltagePin);
float voltage = voltageValue * (5.0 / 1024.0);
lcd.setCursor(0, 0);
lcd.print("Solar: ");
lcd.print(voltage);
lcd.print("V");
} else if (displayMode == 1) {
// Display solar current
int currentValue = analogRead(currentPin);
float current = currentValue * (5.0 / 1024.0);
lcd.setCursor(0, 0);
lcd.print("Battery: ");
lcd.print(current);
lcd.print("A");
} else {
// Display solar power
int voltageValue = analogRead(voltagePin);
float voltage = voltageValue * (5.0 / 1024.0);
int currentValue = analogRead(currentPin);
float current = currentValue * (5.0 / 1024.0);
float power = voltage * current;
lcd.setCursor(0, 0);
lcd.print("Load: ");
lcd.print(power);
lcd.print("W");
}
delay(1000);
}