// Beispiel: Benutzung des ADC am ESP32
// define pin for reading analog values from the potentiometer
const int potPin = 32;
// define the resolution of the ADV
const int resolution = 9;
// variable to save the actual ADC reading
int potValue = 0;
// value to save the actual calculated voltage
float voltValue = 0;
// setup runs once during startup
void setup() {
//set the speed of the serial interface
Serial.begin(115200);
// set the resolution global for all ADC inputs
analogReadResolution(resolution);
// set the attenuation (input value from 0 to 1300mV)
analogSetAttenuation(ADC_6db);
}
void loop() {
// read (convert) the analog value to a int value between 0 and 511 (2^9 values)
potValue = analogRead(potPin);
// write the value
Serial.println(potValue);
// calculate the voltage based on the actual ADC reading
voltValue = (potValue * 3.3) / (pow(2, resolution));
Serial.println("voltage: " + String(voltValue ));
delay(1000); // this speeds up the simulation
}