A demo on NXP KL25Z of the telemetry library to publish some sensor data that can be read/plotted on the computer using pytelemetrycli (https://github.com/Overdrivr/pytelemetrycli) Published data: "touch" -> capacitive slider output value "acc:x" -> x channel of the accelerometer "acc:y" -> y channel "acc:z" -> z channel

Dependencies:   BufferedSerial MMA8451Q mbed telemetry tsi_sensor

Revision:
0:d38b884af46a
Child:
1:b63db8e76533
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+#include "telemetry/driver.hpp"
+#include "tsi_sensor.h"
+#include "MMA8451Q.h"
+ 
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+DigitalOut led(LED1);
+
+struct TM_state {
+  float throttle;  
+};
+
+void process(TM_state* state, TM_msg* msg);
+
+int main()
+{   
+    // Instance the structure holding our application tuning parameters
+    TM_state state;
+    state.throttle = 0;
+    
+    // Instance Telemetry
+    Telemetry TM(&state);
+    // Connect our process function
+    TM.sub(process);
+    
+    // Some sensors to read
+    TSIAnalogSlider tsi(PTB16,PTB17,40);
+    MMA8451Q acc(PTE25, PTE24);
+    
+    led = 1;
+    
+    Timer tm_timer;
+    Timer print_timer;
+    Timer led_timer;
+    
+    tm_timer.start();
+    print_timer.start();
+    
+    for(;;)
+    {       
+        // update telemetry
+        if(tm_timer.read_ms() > 50)
+        {
+            tm_timer.reset();
+            TM.update();   
+        }
+        
+       
+        // publish accelerometer data
+        if(print_timer.read_ms() > 50)
+        {
+            print_timer.reset();
+            TM.pub_f32("touch",tsi.readPercentage());
+            
+            int16_t axis[3];
+            acc.getAccAllAxis(axis);
+            
+            TM.pub_i16("acc:x",axis[0]);
+            TM.pub_i16("acc:y",axis[1]);
+            TM.pub_i16("acc:z",axis[2]);
+            
+            TM.pub_f32("throttle",state.throttle);
+            
+        }
+        
+        if(led_timer.read_ms() > 500)
+        {
+            led_timer.reset();
+            led = (led == 0) ? 1 : 0;  
+        }
+    }
+}
+
+void process(TM_state* state, TM_msg* msg)
+{
+    float value = 0.f;
+    
+    // If the received frame topic matches "throttle"
+    if(strcmp(msg->topic,"throttle") == 0)
+    {
+        // If the payload type matches float32
+        if(emplace_f32(msg,&value))
+        {
+            state->throttle = value; 
+        }
+    }
+}
\ No newline at end of file