#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const int POT_PIN_1 = A1; // Pin A1 for potentiometer1
const int POT_PIN_2 = A2; // Pin A2 for potentiometer2
const float REFERENCE_VOLTAGE_1 = 3.3; // ADC reference voltage
const float REFERENCE_VOLTAGE_2 = 5.0; // ADC reference voltage
// Initialize the I2C LCD interface (address 0x27, 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize serial communication at 9600 baud
Serial.begin(9600);
// Initialize the LCD display
lcd.init();
lcd.backlight();
}
void loop() {
// Read the analog voltage from the potentiometer
int analog_value_1 = analogRead(POT_PIN_1);
// Convert the analog value to a voltage in volts
float voltage_1 = analog_value_1 * (REFERENCE_VOLTAGE_1 / 1023.0);
// Convert the analog value to a string for printing to the LCD display
char analog_string_1[7];
dtostrf(voltage_1, 5, 2, analog_string_1);
int analog_value_2 = analogRead(POT_PIN_2);
// Convert the analog value to a voltage in volts
float voltage_2 = analog_value_2 * (REFERENCE_VOLTAGE_2 / 1023.0);
// Convert the analog value to a string for printing to the LCD display
char analog_string_2[7];
dtostrf(voltage_2, 5, 2, analog_string_2);
// Print the voltage in volts and the digital value in decimal format
// to the LCD display and the serial monitor
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Voltage: ");
lcd.print(analog_string_1);
lcd.print(" V");
lcd.setCursor(0, 1);
lcd.print("Voltage: ");
lcd.print(analog_string_2);
Serial.print("Voltage: ");
Serial.print(analog_string_1);
Serial.print(" V, Digital: ");
Serial.println(analog_value_1);
Serial.print("Voltage: ");
Serial.print(analog_string_2);
Serial.print(" V, Digital: ");
Serial.println(analog_value_2);
delay(100); // Delay for 100 ms before taking the next reading
}