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

Dependencies:   mbed

Revision:
0:c674d8c52a7e
--- /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);
+    }
+}