Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
X-Nucleo-6180XA1 Hello World Application
This application provides a simple example of usage of X_NUCLEO_6180XA1 library. It provides a measurement of:
- Ambient Light (Lux),
- Distance (millimeters) of an object in front of the on-board sensor.
The values are displayed on the Hyperterminal connected through COM port over USB.
Diff: main.cpp
- Revision:
- 35:8b4a5cc0fb1f
- Parent:
- 33:b903a0ec8803
- Child:
- 36:0d4aa5b3234d
--- a/main.cpp Thu Nov 19 14:53:46 2015 +0000
+++ b/main.cpp Tue Nov 24 16:06:03 2015 +0000
@@ -14,7 +14,7 @@
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 */
+ Callback IRQ 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
@@ -125,7 +125,7 @@
printf("Stopped als continuous interrupt measure\n\r");
}
-/* Print on board 4 Digit display the app exiting BYE message */
+/* Print on board 4 Digit display the indicated message <= 4 char */
#define DELAY 2000 // 2Sec
void DisplayMsg(const char * msg)
{
@@ -143,21 +143,17 @@
void IntContinousALSorRangeMeasure (DevI2C device_i2c) {
- // onboard red slider to switch Range/ALS measures
- STMPE1600DigiIn measure_type(device_i2c, GPIO_11);
- int status;
- //device_i2c.frequency(400000); //change i2c frequncy from 100kHz to 400kHz
- //pc.baud(115200); //change the printf baudrate if faster printf is needed
-
- board=X_NUCLEO_6180XA1::Instance(&device_i2c);
+ int status;
+ /* creates the 6180XA1 expansion board singleton obj */
+ board=X_NUCLEO_6180XA1::Instance(&device_i2c, PB_0, PA_4, PA_5, PA_10);
DisplayMsg ("INT");
-
+ /* init the 6180XA1 expansion board with default values */
status=board->InitBoard();
if(status)
printf("Failed to init board!\n\r");
-
-
+ /* check the red slider position for ALS/Range measure */
operating_mode=CheckSlider(IntMeasure);
+ /* start the measure on sensor top */
status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL);
if(!status)
{
@@ -165,105 +161,51 @@
PrintStartMessage(operating_mode);
while(1)
{
- if(int_sensor_top)
+ if(int_sensor_top) /* 6180 isr was triggered */
{
int_sensor_top=false;
- status=board->sensor_top->HandleIRQ(operating_mode, &data_sensor_top);
+ status=board->sensor_top->HandleIRQ(operating_mode, &data_sensor_top); /* handle the isr and read the meaure */
DisplayRefresh(operating_mode);
}
- if(int_stop_measure)
+ if(int_stop_measure) /* Blue Button isr was triggered */
{
- status=board->sensor_top->StopMeasurement(prev_operating_mode);
+ status=board->sensor_top->StopMeasurement(prev_operating_mode); /* stop the measure and exit */
if(!status)
PrintStopMessage(prev_operating_mode);
- int_stop_measure = false;
+ int_stop_measure = false;
printf("\nProgram stopped!\n\n\r");
break;
}
- operating_mode=CheckSlider(IntMeasure);
+ operating_mode=CheckSlider(IntMeasure); /* check if red slider was moved */
if(operating_mode!=prev_operating_mode)
{
DisplayRefresh(prev_operating_mode);
- status=board->sensor_top->StopMeasurement(prev_operating_mode);
+ status=board->sensor_top->StopMeasurement(prev_operating_mode); /* stop the running measure */
if(!status)
PrintStopMessage(prev_operating_mode);
prev_operating_mode=operating_mode;
- status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL);
+ status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, NULL, NULL); /* start the new measure */
if(!status)
PrintStartMessage(operating_mode);
} else
DisplayRefresh(operating_mode);
}
}
- delete board;
+ DisplayMsg("BYE");
+ delete board;
}
-
-void PollContinousALSorRangeMeasure (DevI2C device_i2c) {
- // onboard red slider to switch Range/ALS measures
- STMPE1600DigiIn measure_type(device_i2c, GPIO_11);
- int status;
-
- board=X_NUCLEO_6180XA1::Instance(&device_i2c);
- DisplayMsg ("poll");
- status=board->InitBoard();
- if(status)
- printf("Failed to init board!\n\r");
- operating_mode=CheckSlider(PollMeasure);
- status=board->sensor_top->StartMeasurement(operating_mode, NULL, NULL, NULL);
- if(!status)
- {
- prev_operating_mode=operating_mode;
- PrintStartMessage(operating_mode);
- while(1)
- {
-// do // the loop waiting for the result could be avoided (if is acceptable to get not updated measures)
-// {
- status=board->sensor_top->GetMeasurement(operating_mode, &data_sensor_top);
- DisplayRefresh(operating_mode);
-// }while(status);
-
- if(int_stop_measure)
- {
- status=board->sensor_top->StopMeasurement(prev_operating_mode);
- if(!status)
- PrintStopMessage(prev_operating_mode);
- int_stop_measure = false;
- printf("\nProgram stopped!\n\n\r");
- break;
- }
-
- operating_mode=CheckSlider(PollMeasure);
- if(operating_mode!=prev_operating_mode)
- {
- DisplayRefresh(prev_operating_mode);
- status=board->sensor_top->StopMeasurement(prev_operating_mode);
- if(!status)
- PrintStopMessage(prev_operating_mode);
- prev_operating_mode=operating_mode;
- status=board->sensor_top->StartMeasurement(operating_mode, NULL, NULL, NULL);
- if(!status)
- PrintStartMessage(operating_mode);
- }
- else
- DisplayRefresh(operating_mode);
- }
- }
- DisplayMsg("BYE");
- delete board;
+/*=================================== Main ==================================
+ Move the VL6180X Expansion board red slider to switch between ALS or Range
+ measures.
+ Press the blue user button to stop the measurements in progress
+=============================================================================*/
+int main()
+{
+ InterruptIn stop_button (USER_BUTTON);
+ stop_button.rise (&StopMeasureIRQ);
+ DevI2C device_i2c (VL6180X_I2C_SDA, VL6180X_I2C_SCL);
+
+ IntContinousALSorRangeMeasure (device_i2c); // start continous measures Interrupt based
}
-
-int main()
-{
- /* user button to stop measurements in progress */
- InterruptIn stop_button (USER_BUTTON);
- stop_button.rise (&StopMeasureIRQ);
- DevI2C device_i2c (VL6180X_I2C_SDA, VL6180X_I2C_SCL);
-
- IntContinousALSorRangeMeasure (device_i2c); // start Interrupt continous measures
-
- PollContinousALSorRangeMeasure (device_i2c); // start Polling continous measures
-
-}
-

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor