本站改版新增arduino频道

Micropython
Arduino

arduino 驱动VL6180X光学测距传感器


arduino 驱动VL6180X光学测距传感器

#include <Wire.h>
#include "MHEtLive_VL6180X.h"

MHEtLive_VL6180X vl = MHEtLive_VL6180X();

#include <Adafruit_SSD1306.h>  //1306的库文件
#define OLED_RESET 13                   //设置复位是13号引脚
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
  Serial.begin(115200);
 
 display.begin(SSD1306_SWITCHCAPVCC,0x3C); //刷新
  display.clearDisplay(); //清屏
  display.setTextColor(WHITE);   //字体白色
  display.display();  //显示

  // wait for serial port to open on native usb devices
  while (!Serial) {
    delay(1);
  }
 
  Serial.println("MHEtLive VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  }
  Serial.println("Sensor found!");
}

void loop() {

  
  
  float lux = vl.readLux(VL6180X_ALS_GAIN_5);

  //Serial.print("Lux: "); Serial.println(lux);
  
  uint8_t range = vl.readRange();
  uint8_t status = vl.readRangeStatus();

  if (status == VL6180X_ERROR_NONE) {  
    Serial.print("Range: "); Serial.println(range);
 //*****************************************************
        display.setTextSize(1);       //字体大小为2号
        display.setCursor(35,0); 
        display.print("VL6180");
        display.setCursor(0,12); 
        display.print("Range:");
        display.print(range);
   
//*****************************************************  
  }



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号

执行时间: 0.0096487998962402 seconds