close

利用ESP32的藍芽,將VL53L0X測距結果傳送給UE4

[Arduino 程式 ]

#include<Wire.h>   //匯入I2C標頭檔

#include<VL35L0X.h>   //匯入雷射測距儀標頭檔

#include "BluetoothSerial.h"   //匯入藍芽標頭檔

VL53L0X sensor;   //VL53L0X參考物件名稱為sensor

BluetoothSerial SerialBT;   //藍芽參考物件名稱SrialBT

float Ldistance;     //定義Ldistance為雷射測距的距離(公厘)

void setup() 
{


Serial.begin(115200);  //設定速率為115200
Wire.begin();    //I2C開啟

SerialBT.begin("ESP32test");   //藍芽開啟,命名為"ESP32test"

sensor.setTimeout(500);  //測距所花時間超出500毫秒


  if (!sensor.init())
  {

    Serial.println("Failed to detect and initialize sensor!");
    while (1) {}

  }

//如果沒反應,印出失敗

sensor.startContinuous();

//內定執為100毫秒重製一次

}

void loop()

{

 Ldistance=sensor.readRangeContinuousMillimeters();
//將感應器測到的距離數值放進Ldistance這個變數裡

if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

//SerialBT.write(Ldistance);
 //將Ldistance這個變數送至藍芽通訊模組中,看不懂

 SerialBT.println(Ldistance);
 //將Ldistance這個變數送至藍芽通訊模組中(字串)

delay(50);

}

這樣,ESP32就可利用藍芽將測出的距離傳送出去
 

 
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 a15001500 的頭像
    a15001500

    麵包雜記

    a15001500 發表在 痞客邦 留言(0) 人氣()