Lab2_part2&3&4
Dependencies: 4DGL-uLCD-SE LSM9DS0 mbed
Fork of 4180_LSM9DS0_lab by
Diff: main.cpp
- Revision:
- 6:87468d3886ea
- Parent:
- 4:a9e3007530a7
- Child:
- 7:8c458123a665
diff -r 942e184c4977 -r 87468d3886ea main.cpp --- a/main.cpp Mon Feb 02 21:51:57 2015 +0000 +++ b/main.cpp Sat Sep 05 13:48:58 2015 +0000 @@ -6,7 +6,7 @@ #include "uLCD_4DGL.h" // uncomment this line to enable the uLCD for Part 4 of the lab -//#define PART_4 +#define PART_4 // SDO_XM and SDO_G are pulled up, so our addresses are: #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW @@ -50,15 +50,28 @@ while (true) { - // TODO - add code here to read compass or accelerometer data - // and print it to the USB serial port (part 2) and display it on the uLCD (part 3) - // Compass Trigonometry tip: you can retrieve the compass heading (in degrees) directly from // the IMU library. Example: // imu.readMag(); // float heading = imu.calcHeading(); // Remember that x = length*cos(heading) and y = length*sin(heading) // to convert from degrees to radians (for sin/cos functions), multiply by pi/180 + + // Part 2 read compass heading, accelerometer data, and temperature + // and print it to the USB serial port + imu.readGyro(); + imu.readMag(); + imu.readAccel(); + float heading = imu.calcHeading(); //calculate compass heading + imu.readTemp(); + //pc.printf("Compass heading: %2f\n", heading); +// pc.printf("Accelerometer data: %2f, %2f, %2f\n", imu.ax, imu.ay, imu.az); +// pc.printf("Temperature in Fahr: %3.2f\n", imu.temperature_f); + + //Part3 display it on the uLCD + pc.printf("C: %2f\n", heading); + pc.printf("A: %2f, %2f, %2f\n", imu.ax, imu.ay, imu.az); + pc.printf("T: %3.2f\n", imu.temperature_f); wait_ms(REFRESH_TIME_MS); }