fealkn
Dependencies: mbed LSM9DS1_Library VL53L0X
main.cpp@1:15e0c8f3d4a0, 2021-04-28 (annotated)
- Committer:
- tshin7
- Date:
- Wed Apr 28 19:28:16 2021 +0000
- Revision:
- 1:15e0c8f3d4a0
- Parent:
- 0:ea1c50666fc2
fnlkanfe;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
astovall21 | 0:ea1c50666fc2 | 1 | #include "mbed.h" |
astovall21 | 0:ea1c50666fc2 | 2 | #include <stdio.h> |
astovall21 | 0:ea1c50666fc2 | 3 | #include "LSM9DS1.h" |
tshin7 | 1:15e0c8f3d4a0 | 4 | #include "VL53L0X.h" |
astovall21 | 0:ea1c50666fc2 | 5 | |
astovall21 | 0:ea1c50666fc2 | 6 | DigitalOut myled(LED1); |
astovall21 | 0:ea1c50666fc2 | 7 | |
astovall21 | 0:ea1c50666fc2 | 8 | Serial pc(USBTX,USBRX); |
astovall21 | 0:ea1c50666fc2 | 9 | DigitalOut shdn(p26); |
astovall21 | 0:ea1c50666fc2 | 10 | |
tshin7 | 1:15e0c8f3d4a0 | 11 | LSM9DS1 lol(p9, p10, 0xD6, 0x3C); |
tshin7 | 1:15e0c8f3d4a0 | 12 | I2C i2c(p28, p27); |
tshin7 | 1:15e0c8f3d4a0 | 13 | VL53L0X lidar(&i2c); |
astovall21 | 0:ea1c50666fc2 | 14 | |
astovall21 | 0:ea1c50666fc2 | 15 | int main() |
astovall21 | 0:ea1c50666fc2 | 16 | { |
astovall21 | 0:ea1c50666fc2 | 17 | float tempC; |
astovall21 | 0:ea1c50666fc2 | 18 | shdn = 0; //must reset sensor for an mbed reset to work |
astovall21 | 0:ea1c50666fc2 | 19 | wait(0.1); |
astovall21 | 0:ea1c50666fc2 | 20 | shdn = 1; |
astovall21 | 0:ea1c50666fc2 | 21 | wait(0.1); |
astovall21 | 0:ea1c50666fc2 | 22 | lol.begin(); |
astovall21 | 0:ea1c50666fc2 | 23 | if (!lol.begin()) { |
astovall21 | 0:ea1c50666fc2 | 24 | pc.printf("Failed to communicate with LSM9DS1.\n"); |
astovall21 | 0:ea1c50666fc2 | 25 | } |
astovall21 | 0:ea1c50666fc2 | 26 | lol.calibrate(); |
tshin7 | 1:15e0c8f3d4a0 | 27 | |
astovall21 | 0:ea1c50666fc2 | 28 | //loop taking and printing distance |
astovall21 | 0:ea1c50666fc2 | 29 | while (1) |
astovall21 | 0:ea1c50666fc2 | 30 | { |
astovall21 | 0:ea1c50666fc2 | 31 | lol.readTemp(); |
astovall21 | 0:ea1c50666fc2 | 32 | lol.readMag(); |
astovall21 | 0:ea1c50666fc2 | 33 | lol.readGyro(); |
astovall21 | 0:ea1c50666fc2 | 34 | |
astovall21 | 0:ea1c50666fc2 | 35 | //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); |
astovall21 | 0:ea1c50666fc2 | 36 | //pc.printf("%d %d %d\n\r", lol.calcGyro(lol.gx), lol.calcGyro(lol.gy), lol.calcGyro(lol.gz)); |
astovall21 | 0:ea1c50666fc2 | 37 | pc.printf("gyro: %d %d %d\n\r", lol.gx, lol.gy, lol.gz); |
astovall21 | 0:ea1c50666fc2 | 38 | pc.printf("accel: %d %d %d\n\r", lol.ax, lol.ay, lol.az); |
astovall21 | 0:ea1c50666fc2 | 39 | pc.printf("mag: %d %d %d\n\n\r", lol.mx, lol.my, lol.mz); |
astovall21 | 0:ea1c50666fc2 | 40 | myled = 1; |
astovall21 | 0:ea1c50666fc2 | 41 | wait(2); |
astovall21 | 0:ea1c50666fc2 | 42 | myled = 0; |
astovall21 | 0:ea1c50666fc2 | 43 | wait(2); |
astovall21 | 0:ea1c50666fc2 | 44 | // tempC = myTMP36; |
astovall21 | 0:ea1c50666fc2 | 45 | // pc.printf("Float operator overloading avoids .read(): T=%5.2F C \n\r", tempC); |
astovall21 | 0:ea1c50666fc2 | 46 | // pc.printf("A Printf arg needs a float type convert: T=%5.2F C \n\r", float(myTMP36)); |
astovall21 | 0:ea1c50666fc2 | 47 | // pc.printf("Or Use .read() instead: T=%5.2F C \n\r\n\r", myTMP36.read()); |
astovall21 | 0:ea1c50666fc2 | 48 | // wait(.5); |
astovall21 | 0:ea1c50666fc2 | 49 | |
astovall21 | 0:ea1c50666fc2 | 50 | } |
astovall21 | 0:ea1c50666fc2 | 51 | |
astovall21 | 0:ea1c50666fc2 | 52 | } |