This is a function to determine your Arduino's supply voltage automatically in order to convert
the results of analogRead into a much more accurate voltage. As you may know, analogRead()
returns
a value that's relative to the supply voltage to the Arduino, which can deviate. If you feed a known
voltage to an analog pin, this function can read and use it to calculate what Arduino's supply voltage is:
double getArduinoVcc(int analog_pin, double expected_volt)
{
double received_frac = (double)analogRead(analog_pin) / 1023.0;