Battery Reading

Dependencies:   mbed

Committer:
dnulty
Date:
Fri Nov 08 10:51:33 2019 +0000
Revision:
0:72079b759f8d
Battery Reading

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dnulty 0:72079b759f8d 1 #include "mbed.h"
dnulty 0:72079b759f8d 2
dnulty 0:72079b759f8d 3 AnalogIn v_bat(PB_1);
dnulty 0:72079b759f8d 4 AnalogIn v_5(PC_2);
dnulty 0:72079b759f8d 5 AnalogIn v_3(PF_4);
dnulty 0:72079b759f8d 6 //A2 and A3 for top and base battery charges respectively
dnulty 0:72079b759f8d 7 //cut off voltage at 3.3v or higher - technical max is 4.2v,
dnulty 0:72079b759f8d 8 //but there is no built-in hardware cutoff!
dnulty 0:72079b759f8d 9
dnulty 0:72079b759f8d 10 //MON_VBATT PB_1
dnulty 0:72079b759f8d 11 //MON_5V0 PC_2
dnulty 0:72079b759f8d 12 //MON_3V3 PF_4
dnulty 0:72079b759f8d 13
dnulty 0:72079b759f8d 14 int main() {
dnulty 0:72079b759f8d 15 Serial pc(USBTX, USBRX);
dnulty 0:72079b759f8d 16 while(1) {
dnulty 0:72079b759f8d 17 float analogue5V = v_5.read();
dnulty 0:72079b759f8d 18 float analogue33V = v_3.read();
dnulty 0:72079b759f8d 19 float analogueValue = v_bat.read();
dnulty 0:72079b759f8d 20 pc.printf("Voltage readings are: VBATT: %f 5V0: %f 3V3: %f\n\r", analogueValue, analogue5V, analogue33V);
dnulty 0:72079b759f8d 21 wait_ms(1000);
dnulty 0:72079b759f8d 22 }
dnulty 0:72079b759f8d 23 }