#define MAX_VOLTAGE 5.0
#define POT_RESISTANCE 10000.0
#define MAX_ANALOG_VALUE 1023.0
#define POT_PIN A0
#define DELAY 500
void setup() {
pinMode(POT_PIN, INPUT);
Serial.begin(9600);
}
void loop() {
static uint32_t timer = millis();
int analogValue = analogRead(POT_PIN);
float voltage = analogToVoltage(analogValue);
float resistance = voltageToResistance(voltage);
if((millis() - timer) >= DELAY){
timer = millis();
Serial.print(analogValue);
Serial.print(" ");
Serial.print(voltage);
Serial.print(" ");
Serial.println(resistance);
}
}
float analogToVoltage(int value){
return value * MAX_VOLTAGE / MAX_ANALOG_VALUE;
}
float voltageToResistance(float V){
return POT_RESISTANCE * abs(V-MAX_VOLTAGE) / MAX_VOLTAGE;
}