4180
Dependencies: X_NUCLEO_53L0A1 mbed
Fork of HelloWorld_VL53L0X_LPC1768 by
main.cpp
00001 #include "mbed.h" 00002 #include "XNucleo53L0A1.h" 00003 #include <stdio.h> 00004 Serial pc(USBTX,USBRX); 00005 DigitalOut shdn(p26); 00006 PwmOut speaker(p21); 00007 // This VL53L0X board test application performs a range measurement in polling mode 00008 // Use 3.3(Vout) for Vin, p28 for SDA, p27 for SCL, P26 for shdn on mbed LPC1768 00009 00010 //I2C sensor pins 00011 #define VL53L0_I2C_SDA p28 00012 #define VL53L0_I2C_SCL p27 00013 00014 static XNucleo53L0A1 *board=NULL; 00015 00016 int main() 00017 { 00018 int status; 00019 uint32_t distance; 00020 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); 00021 /* creates the 53L0A1 expansion board singleton obj */ 00022 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2); 00023 shdn = 0; //must reset sensor for an mbed reset to work 00024 wait(0.1); 00025 shdn = 1; 00026 wait(0.1); 00027 /* init the 53L0A1 board with default values */ 00028 status = board->init_board(); 00029 while (status) { 00030 pc.printf("Failed to init board! \r\n"); 00031 status = board->init_board(); 00032 } 00033 //loop taking and printing distance 00034 float freq = 0; 00035 speaker =0.1; //volume 00036 while (1) { 00037 status = board->sensor_centre->get_distance(&distance); 00038 if (status == VL53L0X_ERROR_NONE) { 00039 freq = distance * 1.2; 00040 speaker.period(1.0/freq); // period 00041 } 00042 } 00043 }
Generated on Tue Jul 19 2022 20:45:38 by 1.7.2