Sweep a servo according to Proximity sensor measure

Dependencies:   Servo X_NUCLEO_6180XA1 mbed

Fork of HelloWorld_6180XA1 by ST

Committer:
mapellil
Date:
Mon Sep 12 09:52:06 2016 +0000
Revision:
44:3c68d5aa842e
Parent:
43:f03152407731
Child:
46:43aef8f6e9a0
Extremely simplified the HelloWorld app now consisting in only GetLux and GetDistance synchronous functions calling. Removed the local 4 digit display and the red and the blue button management. The measure results are printed on serial over USB.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gallonm 0:83c628a58feb 1 #include "mbed.h"
gallonm 8:4c05f7a5bb60 2 #include "x_nucleo_6180xa1.h"
gallonm 4:ccd62fd7e137 3 #include <string.h>
gallonm 4:ccd62fd7e137 4 #include <stdlib.h>
gallonm 4:ccd62fd7e137 5 #include <stdio.h>
gallonm 8:4c05f7a5bb60 6 #include <assert.h>
gallonm 8:4c05f7a5bb60 7
mapellil 44:3c68d5aa842e 8 /* This VL6180X Expansion board test application performs a range measurement and als measurement in polling mode
mapellil 30:c8efec21544f 9 on the onboard embedded top sensor.
mapellil 44:3c68d5aa842e 10 The result of both the measures are printed on the serial over.
mapellil 44:3c68d5aa842e 11 GetDistance and GetLux are synchronous!. So they blocks the caller until the result will be ready
mapellil 44:3c68d5aa842e 12 */
gallonm 20:b2e0b41a0e6b 13
mapellil 37:724632fff9c1 14 #define VL6180X_I2C_SDA D14
mapellil 37:724632fff9c1 15 #define VL6180X_I2C_SCL D15
gallonm 5:fa65d931bd96 16
gallonm 27:2afb9baf718f 17 static X_NUCLEO_6180XA1 *board=NULL;
licio.mapelli@st.com 32:724d2afb0ca2 18
mapellil 35:8b4a5cc0fb1f 19 /*=================================== Main ==================================
mapellil 44:3c68d5aa842e 20 Prints on the serial over USB the measured distance and lux.
mapellil 44:3c68d5aa842e 21 The measures are run in single shot polling mode.
mapellil 35:8b4a5cc0fb1f 22 =============================================================================*/
mapellil 35:8b4a5cc0fb1f 23 int main()
mapellil 43:f03152407731 24 {
mapellil 44:3c68d5aa842e 25 int status;
mapellil 44:3c68d5aa842e 26 uint32_t lux, dist;
mapellil 44:3c68d5aa842e 27 DevI2C *device_i2c =new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
mapellil 44:3c68d5aa842e 28 /* creates the 6180XA1 expansion board singleton obj */
mapellil 44:3c68d5aa842e 29 board=X_NUCLEO_6180XA1::Instance(device_i2c, A3, A2, D13, D2);
mapellil 44:3c68d5aa842e 30 /* init the 6180XA1 expansion board with default values */
mapellil 44:3c68d5aa842e 31 status=board->InitBoard();
mapellil 44:3c68d5aa842e 32 if(status) { printf("Failed to init board!\n\r"); return 0; }
mapellil 44:3c68d5aa842e 33 while(1)
mapellil 44:3c68d5aa842e 34 {
mapellil 44:3c68d5aa842e 35 board->sensor_top->GetDistance(&dist);
mapellil 44:3c68d5aa842e 36 board->sensor_top->GetLux(&lux);
mapellil 44:3c68d5aa842e 37 printf ("Distance: %d, Lux: %d\n\r",dist, lux);
mapellil 44:3c68d5aa842e 38 }
gallonm 4:ccd62fd7e137 39 }