初始提交:龙芯2K0300智能车卖家Demo完整代码
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* VL53L0X 激光测距 demo — 持续读取距离并打印
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include "vl53l0x.h"
|
||||
|
||||
std::atomic<bool> running(true);
|
||||
|
||||
void onSignal(int)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::signal(SIGINT, onSignal);
|
||||
|
||||
VL53L0X tof;
|
||||
if (!tof.init())
|
||||
{
|
||||
std::cerr << "VL53L0X 初始化失败" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
VL53L0X_RangingMeasurementData_t data;
|
||||
while (running)
|
||||
{
|
||||
if (tof.readRange(data))
|
||||
{
|
||||
std::cout << "dist=" << data.RangeMilliMeter << "mm"
|
||||
<< " status=" << (int)data.RangeStatus
|
||||
<< " signal=" << data.SignalRateRtnMegaCps
|
||||
<< std::endl;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
tof.stop();
|
||||
std::cout << "VL53L0X demo exit" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user