Sweep a servo according to Proximity sensor measure
Dependencies: Servo X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
Diff: main.cpp
- Revision:
- 20:b2e0b41a0e6b
- Parent:
- 19:394c9a4a3046
- Child:
- 22:bb440c864489
--- a/main.cpp Fri Oct 30 11:59:52 2015 +0100 +++ b/main.cpp Mon Nov 02 14:04:19 2015 +0100 @@ -5,9 +5,19 @@ #include <stdio.h> #include <assert.h> +/* This test application performs a range measurement and an als measurement. + Display select slider allow to switch the measurement type; previuos + measurement is stopped and a new measurement is started. + User button allows to stop current measurement and the entire program. + Reset button is used to restart the program. */ + /* Polling operating modes don`t require callback function that handles IRQ Callback functions are used only for measure that require interrupt */ +/* GetMeasurement is asynchronous! It returns NOT_READY if the measurement value + is not ready to be read from the corresponding register. So you need to wait + for the result to be ready */ + #define VL6180X_I2C_SDA I2C_SDA #define VL6180X_I2C_SCL I2C_SCL @@ -75,7 +85,7 @@ status=board->InitBoard(); if(status) - printf("Failed to init the board!\n\r"); + printf("Failed to init the board!\n\r"); stop_button.rise(&StopMeasureIRQ); measure=measure_type; @@ -83,7 +93,7 @@ operating_mode=range_continuous_interrupt; else if(measure==ALS) operating_mode=als_continuous_interrupt; - status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, &data_sensor_top, NULL, NULL); + status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL); prev_operating_mode=operating_mode; if(!status) { @@ -96,13 +106,9 @@ status=board->sensor_top->HandleIRQ(operating_mode, &data_sensor_top); if(!status) { - if(operating_mode==range_continuous_interrupt) - sprintf(str,"%d",data_sensor_top.range_mm); - else if(operating_mode==als_continuous_interrupt) - sprintf(str,"%d",data_sensor_top.lux); - board->display->DisplayString(str, strlen(str)); + DisplayRefresh(operating_mode); } - /*else + /*else // FIXME va in CRASH se aggiungo queste righe!!!!!!!!!!!!! { sprintf(str,"%s","----"); board->display->DisplayString(str, strlen(str)); @@ -132,7 +138,7 @@ printf("Failed to stop measurement!\n\r"); else printf("Measurement stopped!\n\r"); - status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, &data_sensor_top, NULL, NULL); + status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL); if(status) { printf("\nFailed to start measurement!\n\r"); @@ -147,8 +153,14 @@ } else printf("\nFailed to start measurement!\n\r"); + + for(status=0;status<200;status++) + { + sprintf(str,"%s","CIAO"); + board->display->DisplayString(str, strlen(str)); + } - delete board; + delete board; }