Example code for monitoring battery voltage and lighting a LED when battery voltage is below a threshold.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tylerjw
Date:
Thu Oct 18 20:20:01 2012 +0000
Commit message:
Battery Monitor Demo

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c674d8c52a7e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 18 20:20:01 2012 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+AnalogIn battery(p19);
+DigitalOut battery_warning(p24);
+Serial pc(USBTX, USBRX);
+
+int main() {
+    pc.baud(9600);
+    const float BAT_MUL = 10.26;
+    float sample;
+
+    while(1) {
+        sample = battery.read();
+        pc.printf("VBat: %4.3f, ADC: %4.3f, Vadc: %4.3f\r\n", sample*BAT_MUL, sample, sample*3.3);
+        if(sample*BAT_MUL < 6.4)
+            battery_warning = 0;
+        else
+            battery_warning = 1;
+        wait(1);
+    }
+}
diff -r 000000000000 -r c674d8c52a7e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 18 20:20:01 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc
\ No newline at end of file