4180 Lab 2
Dependencies: mbed wave_player Servo 4DGL-uLCD-SE Motor SDFileSystem LSM9DS1_Library_cal PinDetect X_NUCLEO_53L0A1
sensor_EC.h
00001 #include "mbed.h" 00002 #include "Servo.h" 00003 #include "XNucleo53L0A1.h" 00004 #include <stdio.h> 00005 Serial pc1(USBTX,USBRX); 00006 DigitalOut shdn(p26); 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 Servo servo(p9); 00016 00017 int min_dist = 66536; 00018 int angle = 0; 00019 00020 int run_sensor_EC() { 00021 00022 int status; 00023 uint32_t distance; 00024 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); 00025 /* creates the 53L0A1 expansion board singleton obj */ 00026 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2); 00027 shdn = 0; //must reset sensor for an mbed reset to work 00028 wait(0.1); 00029 shdn = 1; 00030 wait(0.1); 00031 /* init the 53L0A1 board with default values */ 00032 status = board->init_board(); 00033 while (status) { 00034 pc1.printf("Failed to init board! \r\n"); 00035 status = board->init_board(); 00036 } 00037 00038 for (float i = 0.0; i < 1.0; i += 0.1) { 00039 status = board->sensor_centre->get_distance(&distance); 00040 if (status == VL53L0X_ERROR_NONE) { 00041 pc1.printf("D=%ld mm\r\n", distance); 00042 } 00043 if (distance < min_dist) { 00044 min_dist = distance; 00045 angle = i; 00046 } 00047 } 00048 return 0; 00049 }
Generated on Mon Jul 18 2022 11:06:52 by 1.7.2