![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
21/02/18 definitivo
Dependencies: X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
main.cpp
- Committer:
- ornella
- Date:
- 2018-02-21
- Revision:
- 48:256ae4ed9674
- Parent:
- 47:04733a0905ba
File content as of revision 48:256ae4ed9674:
#include "mbed.h" #include "XNucleo6180XA1.h" #include <string.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> #define VL6180X_I2C_SDA D14 #define VL6180X_I2C_SCL D15 static XNucleo6180XA1 *board = NULL; AnalogIn analog_value(A0); DigitalOut tilt(PA_8); DigitalOut pros(PB_10); int main() { float meas; int status; uint32_t lux, dist; DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); /* Creates the 6180XA1 expansion board singleton obj. */ board = XNucleo6180XA1::instance(device_i2c, A3, A2, D13, D2); /* Initializes the 6180XA1 expansion board with default values. */ status = board->init_board(); if (status) { printf("Failed to init board!\n\r"); return 0; } while(1) { meas = analog_value.read(); // It reads the analog input value (value from 0.0 to 1.0) meas = meas * 3300; // Change the value to be in the 0 to 3300 range printf("measure = %.2f mV\r\n", meas); board->sensor_top->get_distance(&dist); board->sensor_top->get_lux(&lux); printf ("Distance: %d, Lux: %d\n\r", dist, lux); if (meas < 2800){ tilt=1; }else{ tilt=0; } if (dist <100){ // If the value is greater than 2.5V and distance is minor of 15cm switch led pros=1; }else{ pros=0; } } }