Lab2_part1
Dependencies: LSM9DS1_Library mbed
main.cpp@2:939da173a4da, 2018-02-08 (annotated)
- Committer:
- bjs9
- Date:
- Thu Feb 08 03:15:37 2018 +0000
- Revision:
- 2:939da173a4da
- Parent:
- 1:3aa43d572cc4
Edit to Code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bjs9 | 0:595b34ef349b | 1 | #include "mbed.h" |
bjs9 | 1:3aa43d572cc4 | 2 | #include "LSM9DS1.h" |
bjs9 | 0:595b34ef349b | 3 | |
bjs9 | 0:595b34ef349b | 4 | DigitalOut myled(LED1); |
bjs9 | 1:3aa43d572cc4 | 5 | Serial pc(USBTX, USBRX); |
bjs9 | 0:595b34ef349b | 6 | |
bjs9 | 0:595b34ef349b | 7 | int main() { |
bjs9 | 1:3aa43d572cc4 | 8 | //LSM9DS1 lol(p9, p10, 0x6B, 0x1E); |
bjs9 | 1:3aa43d572cc4 | 9 | LSM9DS1 lol(p9, p10, 0xD6, 0x3C); |
bjs9 | 1:3aa43d572cc4 | 10 | lol.begin(); |
bjs9 | 1:3aa43d572cc4 | 11 | if (!lol.begin()) { |
bjs9 | 1:3aa43d572cc4 | 12 | pc.printf("Failed to communicate with LSM9DS1.\n"); |
bjs9 | 1:3aa43d572cc4 | 13 | } |
bjs9 | 1:3aa43d572cc4 | 14 | lol.calibrate(); |
bjs9 | 0:595b34ef349b | 15 | while(1) { |
bjs9 | 1:3aa43d572cc4 | 16 | lol.readTemp(); |
bjs9 | 1:3aa43d572cc4 | 17 | lol.readMag(); |
bjs9 | 1:3aa43d572cc4 | 18 | lol.readGyro(); |
bjs9 | 1:3aa43d572cc4 | 19 | |
bjs9 | 1:3aa43d572cc4 | 20 | //pc.printf("%d %d %d %d %d %d %d %d %d\n\r", lol.calcGyro(lol.gx), lol.calcGyro(lol.gy), lol.calcGyro(lol.gz), lol.ax, lol.ay, lol.az, lol.mx, lol.my, lol.mz); |
bjs9 | 1:3aa43d572cc4 | 21 | //pc.printf("%d %d %d\n\r", lol.calcGyro(lol.gx), lol.calcGyro(lol.gy), lol.calcGyro(lol.gz)); |
bjs9 | 1:3aa43d572cc4 | 22 | pc.printf("gyro: %d %d %d\n\r", lol.gx, lol.gy, lol.gz); |
bjs9 | 1:3aa43d572cc4 | 23 | pc.printf("accel: %d %d %d\n\r", lol.ax, lol.ay, lol.az); |
bjs9 | 1:3aa43d572cc4 | 24 | pc.printf("mag: %d %d %d\n\n\r", lol.mx, lol.my, lol.mz); |
bjs9 | 0:595b34ef349b | 25 | myled = 1; |
bjs9 | 1:3aa43d572cc4 | 26 | wait(2); |
bjs9 | 0:595b34ef349b | 27 | myled = 0; |
bjs9 | 1:3aa43d572cc4 | 28 | wait(2); |
bjs9 | 0:595b34ef349b | 29 | } |
bjs9 | 1:3aa43d572cc4 | 30 | } |