E Shibut
/
IMU_Tracker
Reads IMU and pushbutton trigger, writes to PC over serial.
main.cpp@0:5fa2d8adbee6, 2015-12-04 (annotated)
- Committer:
- eshibut3
- Date:
- Fri Dec 04 05:29:39 2015 +0000
- Revision:
- 0:5fa2d8adbee6
Reads in IMU data and checks for pushbutton trigger, writes to PC over serial.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eshibut3 | 0:5fa2d8adbee6 | 1 | #include "mbed.h" |
eshibut3 | 0:5fa2d8adbee6 | 2 | #include "LSM9DS0.h" |
eshibut3 | 0:5fa2d8adbee6 | 3 | |
eshibut3 | 0:5fa2d8adbee6 | 4 | #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW |
eshibut3 | 0:5fa2d8adbee6 | 5 | #define LSM9DS0_G_ADDR 0x6B // Would be 0x6A if SDO_G is LOW |
eshibut3 | 0:5fa2d8adbee6 | 6 | |
eshibut3 | 0:5fa2d8adbee6 | 7 | LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); |
eshibut3 | 0:5fa2d8adbee6 | 8 | Serial pc(USBTX, USBRX); |
eshibut3 | 0:5fa2d8adbee6 | 9 | |
eshibut3 | 0:5fa2d8adbee6 | 10 | //Extra inputs for 'fake' connections, can ignore |
eshibut3 | 0:5fa2d8adbee6 | 11 | DigitalIn in0(p21); |
eshibut3 | 0:5fa2d8adbee6 | 12 | DigitalIn in1(p22); |
eshibut3 | 0:5fa2d8adbee6 | 13 | DigitalIn in2(p23); |
eshibut3 | 0:5fa2d8adbee6 | 14 | DigitalIn in3(p17); |
eshibut3 | 0:5fa2d8adbee6 | 15 | |
eshibut3 | 0:5fa2d8adbee6 | 16 | //Trigger pushbutton |
eshibut3 | 0:5fa2d8adbee6 | 17 | DigitalIn trigger(p15); |
eshibut3 | 0:5fa2d8adbee6 | 18 | |
eshibut3 | 0:5fa2d8adbee6 | 19 | int main() { |
eshibut3 | 0:5fa2d8adbee6 | 20 | //Initialize IMU |
eshibut3 | 0:5fa2d8adbee6 | 21 | imu.begin(); |
eshibut3 | 0:5fa2d8adbee6 | 22 | //Set pushbutton input mode |
eshibut3 | 0:5fa2d8adbee6 | 23 | trigger.mode(PullUp); |
eshibut3 | 0:5fa2d8adbee6 | 24 | while(1) { |
eshibut3 | 0:5fa2d8adbee6 | 25 | imu.readAccel(); |
eshibut3 | 0:5fa2d8adbee6 | 26 | imu.readGyro(); |
eshibut3 | 0:5fa2d8adbee6 | 27 | imu.readMag(); |
eshibut3 | 0:5fa2d8adbee6 | 28 | //IMPORTANT - Unity only recognizes Unix-style line endings in the context of the C# SerialPort.ReadLine() function |
eshibut3 | 0:5fa2d8adbee6 | 29 | pc.printf("%f %f %f$%f %f %f$%f %f %f\r\n", imu.ax, imu.ay, imu.az, imu.gx, imu.gy, imu.gz, imu.mx, imu.my, imu.mz); |
eshibut3 | 0:5fa2d8adbee6 | 30 | wait(.005); |
eshibut3 | 0:5fa2d8adbee6 | 31 | if (!trigger) //Print constant fire string |
eshibut3 | 0:5fa2d8adbee6 | 32 | pc.printf("PEW\r\n"); |
eshibut3 | 0:5fa2d8adbee6 | 33 | } |
eshibut3 | 0:5fa2d8adbee6 | 34 | } |
eshibut3 | 0:5fa2d8adbee6 | 35 |