#include <Wire.h>
#include <LiquidCrystal.h>
// Define the pin where the potentiometer is connected
#define POT_PIN A0 // GP26 corresponds to ADC0
// Initialize the LCD, set the I2C address to 0x27, and the dimensions to 16 columns by 2 rows
LiquidCrystal lcd(28, 27, 22, 6, 21, 20);
void setup() {
// Initialize serial communication at 9600 baud rate
Serial.begin(9600);
// Initialize the LCD
lcd.begin(16, 2);
// Turn on the backlight of the LCD
//lcd.backlight();
// Print a message to the LCD
lcd.setCursor(0, 0);
lcd.print("Voltage: ");
}
void loop() {
// Read the analog value from the potentiometer
int analogValue = analogRead(POT_PIN);
// Convert the analog value (0-4095) to voltage (0-3.3V)
float voltage = analogValue * (3.3 / 4095.0);
// Print the analog value and the corresponding voltage to the Serial Monitor
Serial.print("Analog Value: ");
Serial.print(analogValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.println(" V");
// Display the voltage on the LCD
lcd.setCursor(0, 1); // Set cursor to the beginning of the second line
lcd.print(" "); // Clear the previous voltage reading
lcd.setCursor(0, 1);
lcd.print(voltage, 2); // Print voltage with 2 decimal places
lcd.print(" V");
// Wait a bit before the next loop
delay(500);
}