![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Shows the Battery Voltage
main.cpp@0:8944b0dbd06a, 2013-05-10 (annotated)
- Committer:
- GRG
- Date:
- Fri May 10 13:57:16 2013 +0000
- Revision:
- 0:8944b0dbd06a
Battery Life
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GRG | 0:8944b0dbd06a | 1 | #include "mbed.h" |
GRG | 0:8944b0dbd06a | 2 | |
GRG | 0:8944b0dbd06a | 3 | AnalogIn Battery(p15); |
GRG | 0:8944b0dbd06a | 4 | Serial pc(USBTX, USBRX); |
GRG | 0:8944b0dbd06a | 5 | |
GRG | 0:8944b0dbd06a | 6 | int main() { |
GRG | 0:8944b0dbd06a | 7 | while(1) { |
GRG | 0:8944b0dbd06a | 8 | |
GRG | 0:8944b0dbd06a | 9 | float a, Vcc, R1=46.6, R2=11.92 ; |
GRG | 0:8944b0dbd06a | 10 | |
GRG | 0:8944b0dbd06a | 11 | a=Battery.read(); |
GRG | 0:8944b0dbd06a | 12 | |
GRG | 0:8944b0dbd06a | 13 | Vcc = (a*3.3*(R1+R2)/R2) - 0.32; |
GRG | 0:8944b0dbd06a | 14 | |
GRG | 0:8944b0dbd06a | 15 | pc.printf(" a = %f \n", a); |
GRG | 0:8944b0dbd06a | 16 | pc.printf(" Voltage = %f \n", Vcc); |
GRG | 0:8944b0dbd06a | 17 | wait(1); |
GRG | 0:8944b0dbd06a | 18 | |
GRG | 0:8944b0dbd06a | 19 | |
GRG | 0:8944b0dbd06a | 20 | |
GRG | 0:8944b0dbd06a | 21 | } |
GRG | 0:8944b0dbd06a | 22 | } |