![](/media/cache/group/MFR16-new.png.50x50_q85.jpg)
Sweep a servo according to Proximity sensor measure
Dependencies: Servo X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
main.cpp@46:43aef8f6e9a0, 2016-10-06 (annotated)
- Committer:
- mfr16
- Date:
- Thu Oct 06 10:50:15 2016 +0000
- Revision:
- 46:43aef8f6e9a0
- Parent:
- 44:3c68d5aa842e
Example to sweep a servo according to Proximity sensor measure
;
Who changed what in which revision?
User | Revision | Line number | New 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 | |
mfr16 | 46:43aef8f6e9a0 | 8 | #include "Servo.h" |
mfr16 | 46:43aef8f6e9a0 | 9 | |
mfr16 | 46:43aef8f6e9a0 | 10 | Servo myservo(D3); |
mfr16 | 46:43aef8f6e9a0 | 11 | |
mapellil | 44:3c68d5aa842e | 12 | /* This VL6180X Expansion board test application performs a range measurement and als measurement in polling mode |
mapellil | 30:c8efec21544f | 13 | on the onboard embedded top sensor. |
mapellil | 44:3c68d5aa842e | 14 | The result of both the measures are printed on the serial over. |
mapellil | 44:3c68d5aa842e | 15 | GetDistance and GetLux are synchronous!. So they blocks the caller until the result will be ready |
mapellil | 44:3c68d5aa842e | 16 | */ |
gallonm | 20:b2e0b41a0e6b | 17 | |
mapellil | 37:724632fff9c1 | 18 | #define VL6180X_I2C_SDA D14 |
mapellil | 37:724632fff9c1 | 19 | #define VL6180X_I2C_SCL D15 |
gallonm | 5:fa65d931bd96 | 20 | |
gallonm | 27:2afb9baf718f | 21 | static X_NUCLEO_6180XA1 *board=NULL; |
licio.mapelli@st.com | 32:724d2afb0ca2 | 22 | |
mapellil | 35:8b4a5cc0fb1f | 23 | /*=================================== Main ================================== |
mapellil | 44:3c68d5aa842e | 24 | Prints on the serial over USB the measured distance and lux. |
mapellil | 44:3c68d5aa842e | 25 | The measures are run in single shot polling mode. |
mapellil | 35:8b4a5cc0fb1f | 26 | =============================================================================*/ |
mapellil | 35:8b4a5cc0fb1f | 27 | int main() |
mapellil | 43:f03152407731 | 28 | { |
mapellil | 44:3c68d5aa842e | 29 | int status; |
mapellil | 44:3c68d5aa842e | 30 | uint32_t lux, dist; |
mapellil | 44:3c68d5aa842e | 31 | DevI2C *device_i2c =new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); |
mapellil | 44:3c68d5aa842e | 32 | /* creates the 6180XA1 expansion board singleton obj */ |
mapellil | 44:3c68d5aa842e | 33 | board=X_NUCLEO_6180XA1::Instance(device_i2c, A3, A2, D13, D2); |
mapellil | 44:3c68d5aa842e | 34 | /* init the 6180XA1 expansion board with default values */ |
mapellil | 44:3c68d5aa842e | 35 | status=board->InitBoard(); |
mapellil | 44:3c68d5aa842e | 36 | if(status) { printf("Failed to init board!\n\r"); return 0; } |
mapellil | 44:3c68d5aa842e | 37 | while(1) |
mapellil | 44:3c68d5aa842e | 38 | { |
mapellil | 44:3c68d5aa842e | 39 | board->sensor_top->GetDistance(&dist); |
mapellil | 44:3c68d5aa842e | 40 | board->sensor_top->GetLux(&lux); |
mfr16 | 46:43aef8f6e9a0 | 41 | myservo = (255.0-dist)/255.0; |
mapellil | 44:3c68d5aa842e | 42 | printf ("Distance: %d, Lux: %d\n\r",dist, lux); |
mapellil | 44:3c68d5aa842e | 43 | } |
gallonm | 4:ccd62fd7e137 | 44 | } |