Battery drain test (http://adwiens.com/projects/balloons/batt/index.html)

Dependencies:   mbed-rtos mbed

See http://adwiens.com/projects/balloons/batt/index.html

Files at this revision

API Documentation at this revision

Comitter:
adwiens
Date:
Mon Jan 20 22:48:40 2014 +0000
Commit message:
works great

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jan 20 22:48:40 2014 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "rtos.h"
+
+#define ON_SECS (10)
+#define OFF_SECS (10)
+#define SAMPLE_RATE_HZ (5)
+
+Serial pc(USBTX, USBRX);
+DigitalOut relay(p21);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+AnalogIn adc(p20);
+LocalFileSystem local("local");
+
+double get_voltage(double d) { /* calibrated in freezer */
+    return 8.14*d;
+}
+
+void relay_thr(void const *argument) {
+    int i;
+    while(1) {
+        relay = led1 = 1;
+        for(i=0; i<ON_SECS; ++i) Thread::wait(1000);
+        relay = led1 = 0;
+        for(i=0; i<OFF_SECS; ++i) Thread::wait(1000);
+    }
+}
+
+void log_thr(void const *argument) {
+    FILE *fp = fopen("/local/bv.csv", "a");
+    fprintf(fp,"BEGIN\n");
+    fclose(fp);
+    while(1) {
+        led2 = 1;
+        FILE *fp = fopen("/local/bv.csv", "a");
+        fprintf(fp, "%d,%f\n",(int)relay,get_voltage(adc)-5.0);
+        printf("%d,%f\n",(int)relay,get_voltage(adc)-5.0);
+        fclose(fp);
+        led2 = 0;
+        Thread::wait(1000/SAMPLE_RATE_HZ);
+    }
+}
+
+int main() {
+    Thread relay_thread(relay_thr); // toggles relay
+    Thread log_thread(log_thr); // logs batt voltage
+    while(1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Jan 20 22:48:40 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#29007aef10a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jan 20 22:48:40 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file