schedule sensors at different rates (rates hardcoded)

Dependencies:   mbed

Fork of mbed_test_fastest_rate-bo by Junaid Ahmed

Files at this revision

API Documentation at this revision

Comitter:
tiyasa
Date:
Mon Feb 10 18:58:30 2014 +0000
Parent:
2:ca095bd51302
Commit message:
schedule multiple sensors

Changed in this revision

sensors_scheduled.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ca095bd51302 -r dcbcca17dbfa sensors_scheduled.cpp
--- a/sensors_scheduled.cpp	Mon Feb 10 01:12:28 2014 +0000
+++ b/sensors_scheduled.cpp	Mon Feb 10 18:58:30 2014 +0000
@@ -13,27 +13,43 @@
 AnalogIn lightSensor(PTE22);
 DigitalOut myled(LED1);
 DigitalOut myled2(LED2);
-Timer t;
+Timer tt;
 SLCD slcd;
 TSISensor tsi;
-float accel, magma, light, touch;
 
 int main() {
-        int a, m, l, t = 0, old = 0;
-        t.reset();
-        t.start();
+        float accel, magma, light, touch;
+        int a=0, m=0, l=0, t = 0; 
+        tt.reset();
         while (true){
-            int time = t.read_ms();
-            pc.printf(" time = %d",time);
-            if (time/100 == 0){
-                 accel = acc.getAccX();}
-            if (time%170 == 0){
-                 magma= mag.readVal(MAG_OUT_X_MSB);}
-            if(time%250 == 0){
-                 light = lightSensor.read();}
-            if (time%320 == 0){
-                 touch = tsi.readPercentage();}
-            pc.printf(" acc = %f, mag = %f,light = %f,touch = %f\n", accel, magma, light, touch);
-            }
-    t.stop();
+                    tt.start();
+                 int time = tt.read_ms();
+         //   pc.printf(" time = %d",time);
+            if (a == 0){
+                 accel = acc.getAccX();
+                 a = 10;
+                 }
+                 a--;
+            if (m == 0){
+                 magma= mag.readVal(MAG_OUT_X_MSB);
+                 m =10;
+                 }
+                 m--;
+            if(l == 0){
+                 light = lightSensor.read();
+                 l=10;
+                 }
+                 l--;
+            if (t == 0){
+                 touch = tsi.readPercentage();
+                 t= 10;
+                 }
+                 t--;
+                 
+            pc.printf(" a = %f, m = %f,l = %f,t = %f\n", accel, magma, light, touch);
+            int time1 = tt.read_ms();
+            tt.stop();
+            pc.printf("tt= %d\n",(time1-time));
+            wait((50.0-(time1-time))/1000.0);
+        }
 }
\ No newline at end of file