21/02/18 definitivo
Dependencies: X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
main.cpp@48:256ae4ed9674, 2018-02-21 (annotated)
- Committer:
- ornella
- Date:
- Wed Feb 21 07:42:34 2018 +0000
- Revision:
- 48:256ae4ed9674
- Parent:
- 47:04733a0905ba
21/02/18
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gallonm | 0:83c628a58feb | 1 | #include "mbed.h" |
Davidroid | 47:04733a0905ba | 2 | #include "XNucleo6180XA1.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 | 37:724632fff9c1 | 8 | #define VL6180X_I2C_SDA D14 |
mapellil | 37:724632fff9c1 | 9 | #define VL6180X_I2C_SCL D15 |
gallonm | 5:fa65d931bd96 | 10 | |
Davidroid | 47:04733a0905ba | 11 | static XNucleo6180XA1 *board = NULL; |
Davidroid | 47:04733a0905ba | 12 | |
ornella | 48:256ae4ed9674 | 13 | AnalogIn analog_value(A0); |
ornella | 48:256ae4ed9674 | 14 | DigitalOut tilt(PA_8); |
ornella | 48:256ae4ed9674 | 15 | DigitalOut pros(PB_10); |
licio.mapelli@st.com | 32:724d2afb0ca2 | 16 | |
ornella | 48:256ae4ed9674 | 17 | int main() { |
ornella | 48:256ae4ed9674 | 18 | float meas; |
ornella | 48:256ae4ed9674 | 19 | |
ornella | 48:256ae4ed9674 | 20 | int status; |
ornella | 48:256ae4ed9674 | 21 | uint32_t lux, dist; |
ornella | 48:256ae4ed9674 | 22 | DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); |
ornella | 48:256ae4ed9674 | 23 | |
ornella | 48:256ae4ed9674 | 24 | /* Creates the 6180XA1 expansion board singleton obj. */ |
ornella | 48:256ae4ed9674 | 25 | board = XNucleo6180XA1::instance(device_i2c, A3, A2, D13, D2); |
Davidroid | 47:04733a0905ba | 26 | |
ornella | 48:256ae4ed9674 | 27 | /* Initializes the 6180XA1 expansion board with default values. */ |
ornella | 48:256ae4ed9674 | 28 | status = board->init_board(); |
ornella | 48:256ae4ed9674 | 29 | if (status) { |
ornella | 48:256ae4ed9674 | 30 | printf("Failed to init board!\n\r"); |
ornella | 48:256ae4ed9674 | 31 | return 0; |
ornella | 48:256ae4ed9674 | 32 | } |
ornella | 48:256ae4ed9674 | 33 | while(1) { |
ornella | 48:256ae4ed9674 | 34 | meas = analog_value.read(); // It reads the analog input value (value from 0.0 to 1.0) |
ornella | 48:256ae4ed9674 | 35 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
ornella | 48:256ae4ed9674 | 36 | printf("measure = %.2f mV\r\n", meas); |
Davidroid | 47:04733a0905ba | 37 | |
ornella | 48:256ae4ed9674 | 38 | board->sensor_top->get_distance(&dist); |
ornella | 48:256ae4ed9674 | 39 | board->sensor_top->get_lux(&lux); |
ornella | 48:256ae4ed9674 | 40 | |
ornella | 48:256ae4ed9674 | 41 | printf ("Distance: %d, Lux: %d\n\r", dist, lux); |
ornella | 48:256ae4ed9674 | 42 | if (meas < 2800){ |
ornella | 48:256ae4ed9674 | 43 | tilt=1; |
ornella | 48:256ae4ed9674 | 44 | }else{ |
ornella | 48:256ae4ed9674 | 45 | tilt=0; |
ornella | 48:256ae4ed9674 | 46 | } |
ornella | 48:256ae4ed9674 | 47 | |
ornella | 48:256ae4ed9674 | 48 | if (dist <100){ // If the value is greater than 2.5V and distance is minor of 15cm switch led |
ornella | 48:256ae4ed9674 | 49 | pros=1; |
ornella | 48:256ae4ed9674 | 50 | }else{ |
ornella | 48:256ae4ed9674 | 51 | pros=0; |
ornella | 48:256ae4ed9674 | 52 | } |
ornella | 48:256ae4ed9674 | 53 | } |
ornella | 48:256ae4ed9674 | 54 | } |