Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Distance Measurement
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-21 18:30:28
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* вывод показаний на монитор порта */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_VL53L0X.h> //https://github.com/adafruit/Adafruit_VL53L0X
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void); // Prototype for the updateOutputs function
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t hjb_VL53L0X_GPIO_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t hjb_VL53L0X_XSHUT_PIN_D2 = 2;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t hjb_VL53L0X_I2C_PIN_SDA_A4 = A4;
- const uint8_t hjb_VL53L0X_I2C_PIN_SCL_A5 = A5;
- const uint8_t hjb_VL53L0X_I2C_SLAVE_ADDRESS = 41;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool hjb_VL53L0X_XSHUT_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float hjb_VL53L0X_XSHUT_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- Adafruit_VL53L0X lox = Adafruit_VL53L0X(); // Initialize the VL53L0X object
- void setup(void)
- {
- // Start serial communication at 115200 baud rate
- Serial.begin(115200);
- while (!Serial) delay(1); // Wait for the serial port to open
- // Initialize GPIO and XSHUT pins
- pinMode(hjb_VL53L0X_GPIO_PIN_D3, INPUT_PULLUP);
- pinMode(hjb_VL53L0X_XSHUT_PIN_D2, OUTPUT);
- // Initialize the VL53L0X sensor
- if (!lox.begin()) {
- Serial.println(F("Failed to boot VL53L0X"));
- while(1); // Halt if the sensor fails to initialize
- }
- }
- void loop(void)
- {
- // Refresh output data
- updateOutputs();
- // Create a measurement data structure
- VL53L0X_RangingMeasurementData_t measure;
- lox.rangingTest(&measure, false); // Perform a ranging test
- // Check if the measurement is valid
- if (measure.RangeStatus != 4) {
- // Output the measured distance to the serial monitor
- Serial.print("Distance (mm): ");
- Serial.println(measure.RangeMilliMeter); // Print the measured distance
- } else {
- Serial.println(" out of range "); // Indicate if the measurement is out of range
- }
- delay(100); // Delay for a short period before the next loop iteration
- }
- void updateOutputs()
- {
- // Update the output state
- digitalWrite(hjb_VL53L0X_XSHUT_PIN_D2, hjb_VL53L0X_XSHUT_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement