Thomas Hamilton
/
3DM-GX2
interface class for an inertial measurement unit that uses a serial protocol.
Diff: main.cpp
- Revision:
- 1:555c2c2bf9d3
- Parent:
- 0:fd1fce2347d9
diff -r fd1fce2347d9 -r 555c2c2bf9d3 main.cpp --- a/main.cpp Tue Aug 31 04:38:14 2010 +0000 +++ b/main.cpp Sun Feb 13 10:49:06 2011 +0000 @@ -1,12 +1,41 @@ -#include "mbed.h" - -DigitalOut myled(LED1); - -int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } -} +#include "mbed.h" +#include "MS3DMGX2.h" + +MS3DMGX2 IMU(p9, p10); +DigitalOut led(LED1); +DigitalOut led4(LED4); +Serial PC(USBTX,USBRX); +int main() +{ +led=0; +led4=0; +PC.baud(9600); + float data[9]; + bool isvalid; + wait(1); + isvalid = IMU.Mode(0x05); + PC.printf("Data Valid: %d\r\n\r\n", isvalid); + //IMU.RequestSyncRead(); + wait(1); + + while (1) + { + while(!IMU.Readable()); + isvalid = IMU.Read(data); + + PC.printf("IMU Accel x Reads %f\r\n",data[0]);//NOTE: the compiler will not even calculate unused variables + PC.printf("IMU accel y Reads %f\r\n",data[1]);//If the data retrieved above was not used, it wouldn't even be retrieved and the validity check would not pass + PC.printf("IMU accel z Reads %f\r\n",data[2]);//this is called "compiler optimization" + + PC.printf("IMU ang rate x Reads %f\r\n",data[3]); + PC.printf("IMU ang rate y Reads %f\r\n",data[4]); + PC.printf("IMU ang rate z Reads %f\r\n",data[5]); + + PC.printf("IMU mag x Reads %f\r\n",data[6]); + PC.printf("IMU mag y Reads %f\r\n",data[7]); + PC.printf("IMU mag z Reads %f\r\n",data[8]); + PC.printf("Validity: %d\r\n\r\n", isvalid); + + wait_ms(1000); + } +} \ No newline at end of file