Nora Vazbyte / Mbed 2 deprecated Multi_VL53L0X

Dependencies:   mbed VL53L0X

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "VL53L0X.h"
00003 
00004 #define range1_addr (0x56)
00005 #define range2_addr (0x60)
00006 #define range1_XSHUT   p15
00007 #define range2_XSHUT   p16
00008 #define VL53L0_I2C_SDA   p30 
00009 #define VL53L0_I2C_SCL   p7  
00010  
00011 Serial pc(USBTX, USBRX);
00012 static DevI2C devI2c(VL53L0_I2C_SDA, VL53L0_I2C_SCL); 
00013 DigitalOut led1(LED1);
00014 DigitalOut led2(LED2);
00015  
00016 int main()
00017 {   
00018     /*Contruct the sensors*/ 
00019     static DigitalOut shutdown1_pin(range1_XSHUT);
00020     static VL53L0X range1(&devI2c, &shutdown1_pin, NC);
00021     static DigitalOut shutdown2_pin(range2_XSHUT);
00022     static VL53L0X range2(&devI2c, &shutdown2_pin, NC);
00023     /*Initial all sensors*/   
00024     range1.init_sensor(range1_addr);
00025     range2.init_sensor(range2_addr);
00026 
00027     /*Get datas*/
00028     uint32_t distance1;
00029     uint32_t distance2;
00030     int status1;
00031     int status2;
00032   
00033     while(1){
00034         status1 = range1.get_distance(&distance1);
00035         status2 = range2.get_distance(&distance2);
00036         if (status1 == VL53L0X_ERROR_NONE) {
00037 //            printf("Range1 [mm]:            %6ld\r\n", distance1);
00038             if (distance1 > 40 && distance1 < 2200) {
00039                 led1 = 0;
00040             }
00041             else {
00042                 led1 = 1;
00043             }
00044         } else {
00045 //            printf("Range1 [mm]:                --\r\n");
00046             led1 = 1;
00047         }
00048         if (status2 == VL53L0X_ERROR_NONE) {
00049 //            printf("Range2 [mm]:            %6ld\r\n", distance2);
00050         if (distance2 > 40 && distance2 < 2200) {
00051             led2 = 0;
00052         }
00053         } else {
00054 //            printf("Range2 [mm]:                --\r\n");
00055             led2 = 1;
00056         }
00057         wait(0.2);                 
00058     }
00059  
00060 }
00061