拓郎 松坂 / Mbed 2 deprecated LPC1768_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   p8  //D7
00007 #define range2_XSHUT   p9   //D8
00008 #define VL53L0_I2C_SDA   p28  //D14 
00009 #define VL53L0_I2C_SCL   p27  //D15  
00010  
00011 Serial pc(USBTX, USBRX);
00012 Timer       t;
00013 static DevI2C devI2c(VL53L0_I2C_SDA,VL53L0_I2C_SCL); 
00014  
00015 int main()
00016 {   
00017     /*Contruct the sensors*/ 
00018     static DigitalOut shutdown1_pin(range1_XSHUT);
00019     static VL53L0X range1(&devI2c, &shutdown1_pin, NC);
00020     static DigitalOut shutdown2_pin(range2_XSHUT);
00021     static VL53L0X range2(&devI2c, &shutdown2_pin, NC);
00022     /*Initial all sensors*/   
00023     range1.init_sensor(range1_addr);
00024     range2.init_sensor(range2_addr);
00025 
00026     /*Get datas*/
00027     uint32_t distance1;
00028     uint32_t distance2;
00029     int status1;
00030     int status2;
00031     uint32_t tm_all_work;
00032     
00033     while(1){
00034         t.reset();
00035         t.start();
00036         status1 = range1.get_distance(&distance1);
00037         if (status1 == VL53L0X_ERROR_NONE) {
00038             printf("Range1 [mm]:         %6ld  ", distance1);
00039         } else {
00040             printf("Range1 [mm]:             --  ");
00041         }
00042 
00043         status2 = range2.get_distance(&distance2);
00044         if (status2 == VL53L0X_ERROR_NONE) {
00045             printf("Range2 [mm]:         %6ld\r\n", distance2);
00046         } else {
00047             printf("Range2 [mm]:             --\r\n");
00048         }
00049         tm_all_work = t.read_ms();
00050         if (tm_all_work < 99){
00051             wait_ms(100 - tm_all_work);
00052         }
00053         pc.printf("   %d  \r\n", tm_all_work);
00054     }
00055  
00056 }
00057