ECE 4180 Lab 2 Part 16

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of HelloWorld_VL53L0X_LPC1768 by jim hamblen

Committer:
johnAlexander
Date:
Thu Dec 01 14:19:01 2016 +0000
Revision:
3:b3f70617a6b3
Parent:
1:3483e701ec59
Child:
4:c8932fb926d6
Simplify example, to be simplest possible ranging example. Print range measurements rather than send them to the 4-digit display.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:ce8359133ae6 1 #include "mbed.h"
johnAlexander 0:ce8359133ae6 2 #include "x_nucleo_53l0a1.h"
johnAlexander 0:ce8359133ae6 3 #include <string.h>
johnAlexander 0:ce8359133ae6 4 #include <stdlib.h>
johnAlexander 0:ce8359133ae6 5 #include <stdio.h>
johnAlexander 0:ce8359133ae6 6 #include <assert.h>
johnAlexander 0:ce8359133ae6 7
johnAlexander 1:3483e701ec59 8 /* This VL53L0X Expansion board test application performs a range measurement in polling mode
johnAlexander 0:ce8359133ae6 9 on the onboard embedded top sensor.
johnAlexander 1:3483e701ec59 10 The measured data is displayed on the on-board 4-digit display.
johnAlexander 0:ce8359133ae6 11
johnAlexander 1:3483e701ec59 12 User Blue button stops the current measurement and the entire program, releasing all resources.
johnAlexander 0:ce8359133ae6 13 Reset button is used to restart the program. */
johnAlexander 0:ce8359133ae6 14
johnAlexander 0:ce8359133ae6 15 /* Polling operating modes don`t require callback function that handles IRQ
johnAlexander 0:ce8359133ae6 16 Callback IRQ functions are used only for measure that require interrupt */
johnAlexander 0:ce8359133ae6 17
johnAlexander 0:ce8359133ae6 18 /* GetMeasurement is asynchronous! It returns NOT_READY if the measurement value
johnAlexander 0:ce8359133ae6 19 is not ready to be read from the corresponding register. So you need to wait
johnAlexander 0:ce8359133ae6 20 for the result to be ready */
johnAlexander 0:ce8359133ae6 21
johnAlexander 0:ce8359133ae6 22 #define VL53L0_I2C_SDA D14
johnAlexander 0:ce8359133ae6 23 #define VL53L0_I2C_SCL D15
johnAlexander 0:ce8359133ae6 24
johnAlexander 0:ce8359133ae6 25 static X_NUCLEO_53L0A1 *board=NULL;
johnAlexander 1:3483e701ec59 26
johnAlexander 0:ce8359133ae6 27
johnAlexander 0:ce8359133ae6 28 /*=================================== Main ==================================
johnAlexander 0:ce8359133ae6 29 =============================================================================*/
johnAlexander 0:ce8359133ae6 30 int main()
johnAlexander 0:ce8359133ae6 31 {
johnAlexander 3:b3f70617a6b3 32 int status;
johnAlexander 3:b3f70617a6b3 33 uint32_t distance;
johnAlexander 3:b3f70617a6b3 34 DevI2C *device_i2c =new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 3:b3f70617a6b3 35
johnAlexander 3:b3f70617a6b3 36 /* creates the 53L0A1 expansion board singleton obj */
johnAlexander 3:b3f70617a6b3 37 board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);
johnAlexander 3:b3f70617a6b3 38
johnAlexander 3:b3f70617a6b3 39 /* init the 53L0A1 expansion board with default values */
johnAlexander 3:b3f70617a6b3 40 status=board->InitBoard();
johnAlexander 3:b3f70617a6b3 41 if(status) { printf("Failed to init board!\n\r"); return 0; }
johnAlexander 3:b3f70617a6b3 42 while(1)
johnAlexander 3:b3f70617a6b3 43 {
johnAlexander 3:b3f70617a6b3 44 board->sensor_centre->GetDistance(&distance);
johnAlexander 3:b3f70617a6b3 45 printf("Distance : %ld\n", distance);
johnAlexander 3:b3f70617a6b3 46 }
johnAlexander 0:ce8359133ae6 47 }
johnAlexander 0:ce8359133ae6 48