Skip to content

Instantly share code, notes, and snippets.

@Overdrivr
Created Feb 15, 2016
Embed
What would you like to do?
Output sensor data from NXP KL25Z using the telemetry library(http://bit.ly/1XtKWXS) to a computer. With the command-line interface(http://bit.ly/20TuTrY), plots of the sensors data can be opened by typing a few commands.
#include "mbed.h"
#include "telemetry/driver.hpp"
#include "tsi_sensor.h"
#include "MMA8451Q.h"
#define MMA8451_I2C_ADDRESS (0x1d<<1)
int main()
{
Telemetry TM();
// Init some sensors to read
TSIAnalogSlider tsi(PTB16,PTB17,40);
MMA8451Q acc(PTE25, PTE24);
// A timer to limit publish rate
Timer tm_timer;
tm_timer.start();
//An array for accelerometer values
int16_t axis[3];
for(;;)
{
if(tm_timer.read_ms() > 50)
{
tm_timer.reset();
acc.getAccAllAxis(axis);
TM.pub_f32("touch",tsi.readPercentage());
TM.pub_i16("accx",axis[0]);
TM.pub_i16("accy",axis[1]);
TM.pub_i16("accz",axis[2]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment