ECE 4180 Lab 2 Part 16

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of HelloWorld_VL53L0X_LPC1768 by jim hamblen

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 Serial pc(USBTX,USBRX);
00005 DigitalOut shdn(p26);
00006 // This VL53L0X board test application performs a range measurement in polling mode
00007 // Use 3.3(Vout) for Vin, p28 for SDA, p27 for SCL, P26 for shdn on mbed LPC1768
00008 
00009 //I2C sensor pins
00010 #define VL53L0_I2C_SDA   p28
00011 #define VL53L0_I2C_SCL   p27
00012 
00013 static XNucleo53L0A1 *board=NULL;
00014 
00015 int main()
00016 {
00017     int status;
00018     uint32_t distance;
00019     DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
00020     /* creates the 53L0A1 expansion board singleton obj */
00021     board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
00022     shdn = 0; //must reset sensor for an mbed reset to work
00023     wait(0.1);
00024     shdn = 1;
00025     wait(0.1);
00026     /* init the 53L0A1 board with default values */
00027     status = board->init_board();
00028     while (status) {
00029         pc.printf("Failed to init board! \r\n");
00030         status = board->init_board();
00031     }
00032     //loop taking and printing distance
00033     while (1) {
00034         status = board->sensor_centre->get_distance(&distance);
00035         if (status == VL53L0X_ERROR_NONE) {
00036             pc.printf("D=%ld mm\r\n", distance);
00037         }
00038     }
00039 }