gpt4 book ai didi

c++ - 如何使用移位运算符 << 分配 BH1750 光传感器中的值?

转载 作者:行者123 更新时间:2023-11-30 04:46:53 24 4
gpt4 key购买 nike

<分区>

我使用带有 arduino 的 BH1750 光传感器在 LCD 上显示勒克斯值。但是在代码中,我无法获得公式。谁能给我解释一下公式?

我试图在 BH1750 的数据表中找到它,但我无法理解这一行:

value = ((buff[0]<<8)|buff[1])/1.2;

完整代码:

#include<Wire.h>
#include<LiquidCrystal.h>

int BH1750address = 0x23;
byte buff[2];
LiquidCrystal lcd (7,6,5,4,3,2); //RS, E, D4, D5, D6, D7

void setup()
{
Wire.begin();
lcd.begin(16,2);
lcd.print(" BH1750 Light ");
lcd.setCursor(0,1);
lcd.print("Intensity Sensor");
delay(2000);
}

void loop()
{
int i;
uint16_t value=0;
BH1750_Init(BH1750address);
delay(200);

if(2==BH1750_Read(BH1750address))
{
value=((buff[0]<<8)|buff[1])/1.2; //This is where the problem is
lcd.clear();
lcd.print("Intensity in LUX");
lcd.setCursor(6,1);
lcd.print(value);
}
delay(150);
}

int BH1750_Read(int address)
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available())
{
buff[i] = Wire.read();
i++;
}
Wire.endTransmission();
return i;
}

void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);
Wire.endTransmission();
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com