Skip to content

Instantly share code, notes, and snippets.

@Overdrivr
Created February 15, 2016 21:28
Show Gist options
  • Save Overdrivr/ccbdf662d6c5890cf009 to your computer and use it in GitHub Desktop.
Save Overdrivr/ccbdf662d6c5890cf009 to your computer and use it in GitHub Desktop.
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