/**
* ******************************************************************************
* @file Arduino_Nano_VL53L0X_DataLogTerminal.ino
* @author CLAB
* @version V1.0.0
* @date 07 July 2017
* @brief Arduino test application for the Arduino Nano
* based on FlightSense.
* This application makes use of C++ classes obtained from the C
* components' drivers.
******************************************************************************
* @attention
*
*
© COPYRIGHT(c) 2018 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include
#include
// Create components.
VL53L0X *sensor_vl53l0x;
/* Setup ---------------------------------------------------------------------*/
void setup() {
int status;
// Led.
pinMode(13, OUTPUT);
// Initialize serial for output.
Serial.begin(9600);
// Initialize I2C bus.
Wire.begin();
sensor_vl53l0x = new VL53L0X(&Wire, 5, 6); //XSHUT=5 & INT=6
// Switch off VL53L0X component.
sensor_vl53l0x->VL53L0X_Off();
// Initialize VL53L0X top component.
status = sensor_vl53l0x->InitSensor(0x10);
if(status)
{
Serial.println("Init sensor_vl53l0x failed...");
}
}
/* Loop ----------------------------------------------------------------------*/
void loop() {
// Led blinking.
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
// Read Range.
uint32_t distance;
int status;
status = sensor_vl53l0x->GetDistance(&distance);
if (status == VL53L0X_ERROR_NONE)
{
// Output data.
char report[64];
snprintf(report, sizeof(report), "| Distance [mm]: %ld |", distance);
Serial.println(report);
}
}