志鈴 謝 / Mbed 2 deprecated VL53L0X

Dependencies:   mbed X_NUCLEO_53L0A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "XNucleo53L0A1.h"
00003 #include <stdio.h>
00004  
00005 /* This VL53L0X Expansion board test application performs a range measurement in polling mode
00006    on the onboard embedded top sensor. */
00007  
00008 #define VL53L0_I2C_SDA   D14 
00009 #define VL53L0_I2C_SCL   D15 
00010 DigitalOut XSHUT(D7); 
00011 static XNucleo53L0A1 *board=NULL;
00012  
00013  
00014 /*=================================== Main ==================================
00015 =============================================================================*/
00016 int main()
00017 {   
00018    int status;
00019    uint32_t distance;
00020     
00021     XSHUT = 1;
00022     
00023     DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
00024     
00025     /* creates the 53L0A1 expansion board singleton obj */
00026     board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
00027  
00028     /* init the 53L0A1 expansion board with default values */
00029     status = board->init_board();
00030     if (status) {
00031         printf("Failed to init board!\r\n");
00032         return 0;
00033     }
00034  
00035    while (1) {
00036         status = board->sensor_centre->get_distance(&distance);
00037         if (status == VL53L0X_ERROR_NONE) {
00038            printf("Distance : %ld\r\n", distance);
00039         }
00040    }
00041 }