offline test

Dependencies:   mbed VL53L0X

Committer:
jkjk010695
Date:
Thu Jan 25 06:37:33 2018 +0000
Revision:
0:c543582b78b1
Child:
1:5bb2524b423c
Use several VL53L0X sensors with a pair I2C pins

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jkjk010695 0:c543582b78b1 1 #include "mbed.h"
jkjk010695 0:c543582b78b1 2 #include "VL53L0X.h"
jkjk010695 0:c543582b78b1 3
jkjk010695 0:c543582b78b1 4 #define range1_addr (0x56)
jkjk010695 0:c543582b78b1 5 #define range2_addr (0x60)
jkjk010695 0:c543582b78b1 6 #define range1_XSHUT D7
jkjk010695 0:c543582b78b1 7 #define range2_XSHUT D8
jkjk010695 0:c543582b78b1 8 #define VL53L0_I2C_SDA D14
jkjk010695 0:c543582b78b1 9 #define VL53L0_I2C_SCL D15
jkjk010695 0:c543582b78b1 10
jkjk010695 0:c543582b78b1 11 Serial pc(SERIAL_TX, SERIAL_RX);
jkjk010695 0:c543582b78b1 12 static DevI2C devI2c(VL53L0_I2C_SDA,VL53L0_I2C_SCL);
jkjk010695 0:c543582b78b1 13
jkjk010695 0:c543582b78b1 14 int main()
jkjk010695 0:c543582b78b1 15 {
jkjk010695 0:c543582b78b1 16 /*Contruct the sensors*/
jkjk010695 0:c543582b78b1 17 static DigitalOut shutdown1_pin(range1_XSHUT);
jkjk010695 0:c543582b78b1 18 static VL53L0X range1(&devI2c, &shutdown1_pin, NC);
jkjk010695 0:c543582b78b1 19 static DigitalOut shutdown2_pin(range2_XSHUT);
jkjk010695 0:c543582b78b1 20 static VL53L0X range2(&devI2c, &shutdown2_pin, NC);
jkjk010695 0:c543582b78b1 21 /*Initial all sensors*/
jkjk010695 0:c543582b78b1 22 range1.init_sensor(range1_addr);
jkjk010695 0:c543582b78b1 23 range2.init_sensor(range2_addr);
jkjk010695 0:c543582b78b1 24
jkjk010695 0:c543582b78b1 25 /*Get datas*/
jkjk010695 0:c543582b78b1 26 uint32_t distance1;
jkjk010695 0:c543582b78b1 27 uint32_t distance2;
jkjk010695 0:c543582b78b1 28 int status1;
jkjk010695 0:c543582b78b1 29 int status2;
jkjk010695 0:c543582b78b1 30 while(1){
jkjk010695 0:c543582b78b1 31 status1 = range1.get_distance(&distance1);
jkjk010695 0:c543582b78b1 32 if (status1 == VL53L0X_ERROR_NONE) {
jkjk010695 0:c543582b78b1 33 printf("Range1 [mm]: %6ld\r\n", distance1);
jkjk010695 0:c543582b78b1 34 } else {
jkjk010695 0:c543582b78b1 35 printf("Range1 [mm]: --\r\n");
jkjk010695 0:c543582b78b1 36 }
jkjk010695 0:c543582b78b1 37
jkjk010695 0:c543582b78b1 38 status2 = range2.get_distance(&distance2);
jkjk010695 0:c543582b78b1 39 if (status2 == VL53L0X_ERROR_NONE) {
jkjk010695 0:c543582b78b1 40 printf("Range2 [mm]: %6ld\r\n", distance2);
jkjk010695 0:c543582b78b1 41 } else {
jkjk010695 0:c543582b78b1 42 printf("Range2 [mm]: --\r\n");
jkjk010695 0:c543582b78b1 43 }
jkjk010695 0:c543582b78b1 44 wait(0.5);
jkjk010695 0:c543582b78b1 45 }
jkjk010695 0:c543582b78b1 46
jkjk010695 0:c543582b78b1 47 }
jkjk010695 0:c543582b78b1 48