qwerty

Dependencies:   mbed mbed

Fork of battery_monitor_demo by Tyler Weaver

Committer:
tylerjw
Date:
Thu Oct 18 20:20:01 2012 +0000
Revision:
0:c674d8c52a7e
Child:
1:09b1d08854b6
Battery Monitor Demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:c674d8c52a7e 1 #include "mbed.h"
tylerjw 0:c674d8c52a7e 2
tylerjw 0:c674d8c52a7e 3 DigitalOut myled(LED1);
tylerjw 0:c674d8c52a7e 4 AnalogIn battery(p19);
tylerjw 0:c674d8c52a7e 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 }