qwerty
Fork of battery_monitor_demo by
main.cpp@1:09b1d08854b6, 2017-08-29 (annotated)
- Committer:
- dabraham
- Date:
- Tue Aug 29 00:30:08 2017 +0000
- Revision:
- 1:09b1d08854b6
- Parent:
- 0:c674d8c52a7e
qwerty
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tylerjw | 0:c674d8c52a7e | 1 | #include "mbed.h" |
| tylerjw | 0:c674d8c52a7e | 2 | |
| dabraham | 1:09b1d08854b6 | 3 | //DigitalOut myled(LED1); |
| tylerjw | 0:c674d8c52a7e | 4 | AnalogIn battery(p19); |
| dabraham | 1:09b1d08854b6 | 5 | //DigitalOut battery_warning(p24); |
| tylerjw | 0:c674d8c52a7e | 6 | Serial pc(USBTX, USBRX); |
| tylerjw | 0:c674d8c52a7e | 7 | |
| tylerjw | 0:c674d8c52a7e | 8 | int main() { |
| tylerjw | 0:c674d8c52a7e | 9 | pc.baud(9600); |
| tylerjw | 0:c674d8c52a7e | 10 | const float BAT_MUL = 10.26; |
| tylerjw | 0:c674d8c52a7e | 11 | float sample; |
| tylerjw | 0:c674d8c52a7e | 12 | |
| tylerjw | 0:c674d8c52a7e | 13 | while(1) { |
| tylerjw | 0:c674d8c52a7e | 14 | sample = battery.read(); |
| tylerjw | 0:c674d8c52a7e | 15 | pc.printf("VBat: %4.3f, ADC: %4.3f, Vadc: %4.3f\r\n", sample*BAT_MUL, sample, sample*3.3); |
| tylerjw | 0:c674d8c52a7e | 16 | if(sample*BAT_MUL < 6.4) |
| tylerjw | 0:c674d8c52a7e | 17 | battery_warning = 0; |
| tylerjw | 0:c674d8c52a7e | 18 | else |
| tylerjw | 0:c674d8c52a7e | 19 | battery_warning = 1; |
| tylerjw | 0:c674d8c52a7e | 20 | wait(1); |
| tylerjw | 0:c674d8c52a7e | 21 | } |
| tylerjw | 0:c674d8c52a7e | 22 | } |
