1 Star 0 Fork 0

vuitech/M5FactoryTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BH1750.cpp 798 Bytes
一键复制 编辑 原始数据 按行查看 历史
李辉 提交于 2022-12-10 22:46 +08:00 . 修改光照代码
#include <Wire.h>
#include <math.h>
#include <Arduino.h>
//#include <MsTimer2.h>
#define SDA_PIN 21
#define SCL_PIN 22
int BH1750address = 0x23;//BH1750 I2C地址0x23 //ADDR="L" for this module
int BH1750() //BH1750设备操作
{
unsigned char buff[2];
int i=0;
double val=0;
//开始I2C读写操作
Wire.beginTransmission(BH1750address);
Wire.write(0x10);//1lx reolution 120ms//发送命令
Wire.endTransmission();
delay(200);
//读取数据
// Wire.beginTransmission(BH1750address);
//delay(120);
Wire.requestFrom(BH1750address, 2);
while(Wire.available())
{
// Serial.println("2");
buff[i] = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
if(2==i)
{
val=((buff[0]<<8)|buff[1])/1.2;
}
return val;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/vuitech/FactoryTest.git
git@gitee.com:vuitech/FactoryTest.git
vuitech
FactoryTest
M5FactoryTest
master

搜索帮助