#include <LiquidCrystal.h> // include standard LCD library
LiquidCrystal lcd(5,18,19,21,22,23); // assign pins as RS, E, D4, D5, D6, D7
// Potentiometers are connected to GPIO 34 and 35
const int potPin1 = 34;
const int potPin2 = 35;
// Declare integers for potentiometer value
int pot1Value = 0;
int pot2Value = 0;
// Declare floats for potentiometer voltage
float pot1Voltage = 0.00;
float pot2Voltage = 0.00;
void setup() {
Serial.begin(115200);
lcd.begin(16,2);
delay(100);
// pinMode(potPin1,INPUT_PULLUP);
}
void loop() {
// Measures the value of the potentiometer
pot1Value = analogRead(potPin1);
pot1Voltage = 3.3 * analogRead(potPin1)/4095;
pot2Value = analogRead(potPin2);
pot2Voltage = 3.3 * pot2Value/4095;
Serial.println((String)pot1Value + " " + (String)pot2Value);
Serial.println((String)pot1Voltage + "V, " + (String)pot2Voltage + "V");
lcd.clear();
lcd.setCursor(0,0);
lcd.println((String)pot1Value + " " + (String)pot2Value);
lcd.setCursor(0,1);
lcd.println((String)pot1Voltage + "V " + (String)pot2Voltage + "V");
delay(500);
}
/*
void setup() {
Serial.begin(115200);
analogSetAttenuation(ADC_0db);
Serial.println("Hello, ESP32!");
lcd.begin(16,2); // specify 16-column 2-row LCD
//lcd.backlight(); // no function for most LCDs
lcd.setCursor(1, 0);
lcd.print("Hello, Wokwi!");
delay(1000);
}
void loop()
{
lcd.clear();
ADCvalue = analogRead(ADCpin);
Serial.print("ADC Value: ");
Serial.println(ADCvalue);
ADCvoltage = (ADCvalue * 3.3) / 4095;
actual_voltage = ADCvoltage * 6;
lcd.setCursor(0,0); // set cursor to first column, first row
lcd.print("ADC Value:"); // print message
lcd.setCursor(11,0); // set cursor to 12th column, first row
lcd.print(ADCvalue);
lcd.setCursor(0,1);
lcd.print("Voltage: ");
lcd.print(actual_voltage);
lcd.print("V");
delay(500);
lcd.clear();
delay(10); // this speeds up the simulation
}
/*
int analogvalue = analogRead(A0);
temp = (analogvalue * 5.0) / 1024.0; // FORMULA USED TO CONVERT THE VOLTAGE
input_volt = temp / (r2/(r1+r2));
if (input_volt < 0.1)
{
input_volt=0.0;
}
Serial.print("v= "); // prints the voltage value in the serial monitor
Serial.println(input_volt);
lcd.setCursor(0, 1);
lcd.print("Voltage: "); // prints the voltage value in the LCD display
lcd.print(input_volt);
delay(300);
*/