the disadvantage of float calculation,
Let me assume that you apply the adjustable voltage to R1, connect the Attiny between R1 & R2, and R2 to GND, which would make sense to be able to extend the range in which you can measure voltage by 6 times.
Then you calculation is correct.
voltage = value * ( 5.0 / 1024 ) * ( (R1 + R2) / R2);
(actually it should be (5.0 / 1023) but that is a minor detail )
How have you wired things up exactly. Keep in kind that the ADC is wired differently to the normal GPIO pin names.
Are you sure VCC stays 5.0volt when you adjust voltage divider input.
Because this sketch uses default Aref, which makes the result dependent on both A2 and VCC.
For voltage measurements you should use the internal reference (1.1volt Aref) of the chip.
Especially when VCC does not stay 5.0volt.
Leo..
If you use the internal reference you may need to calibrate for the actual value. It is stable, but the actual value may vary by ~10% from the 1.1V for a given chip.
Hi buddy, I hope you would have been successful in your project... would you be able to share the final code to read the supply voltage of Attiny13 accurately ?