Playing around with accelerometer and magnetometer on mbed KL46Z
Dependencies: MAG3110 MMA8451Q PinDetect mbed TSI
Diff: main.cpp
- Revision:
- 6:52474f03f1ff
- Parent:
- 5:4ccda4b4f345
--- a/main.cpp Mon Feb 03 05:38:17 2014 +0000 +++ b/main.cpp Mon Feb 03 23:09:01 2014 +0000 @@ -3,6 +3,7 @@ #include "MMA8451Q.h" #include "MAG3110.h" #include "TSISensor.h" +#include "serialCom.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) @@ -45,6 +46,17 @@ void lightTime(); void touchTime(); +// Interupt Routine to write out data to serial port +void Tx_interrupt() { +// Loop to fill more than one character in UART's transmit FIFO buffer +// Stop if buffer empty + while ((pc.writeable()) && (tx_in != tx_out)) { + pc.putc(tx_buffer[tx_out]); + tx_out = (tx_out + 1) % buffer_size; + } + return; +} + void init() { // Attach timerAcc @@ -54,6 +66,7 @@ timerTouch.attach(&touchTime, 0.05); ledred = 0; ledgreen = 0; + pc.attach(&Tx_interrupt, Serial::TxIrq); } int main() @@ -64,7 +77,8 @@ while(1) { // read all sensor data - pc.printf("%f %f %f %d %d %d %f %f\n", xAcc, yAcc, zAcc, xMag, yMag, zMag, xLight, xTouch); + sprintf(tx_line,"Hello world\r\n", xMag, yMag); + send_line(pc); wait(0.05); } }