用户工具

站点工具


ocrobot:sensor_suite:bh1750:main

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

后一修订版
前一修订版
ocrobot:sensor_suite:bh1750:main [2019/06/14 09:05]
董凯萍 创建
ocrobot:sensor_suite:bh1750:main [2019/12/23 03:51] (当前版本)
董凯萍 [代码]
行 13: 行 13:
   - OCROBOT ALPHA 双路锂电池扩展板   - OCROBOT ALPHA 双路锂电池扩展板
   
 +==== 代码 ====
 +<code cpp>
 +#include <​Wire.h>​
 +#include <​LiquidCrystal_I2C.h>​
 +#define ADDR 0b0100011
 +LiquidCrystal_I2C lcd(0x20, 16, 2);
 +void setup() {
 +  // put your setup code here, to run once:
 +  Serial.begin(9600);​
 +  Wire.begin(); ​    
 +  Wire.beginTransmission(ADDR);​
 +  Wire.write(0b00000001);​
 +  Wire.endTransmission();​
 +  lcd.init(); ​                  //​初始化屏幕
 +  lcd.backlight();​
 +}
  
 +void loop() {
 +  // put your main code here, to run repeatedly: ​
 +  int val = 0;
 +
 +  // reset
 +  Wire.beginTransmission(ADDR);​
 +  Wire.write(0b00000111);​
 +  Wire.endTransmission();​
 +
 +  delay(100);
 +
 +
 +
 +  Wire.beginTransmission(ADDR);​
 +  Wire.write(0b00100000);​
 +  Wire.endTransmission();​
 +
 +  // typical read delay 120ms
 +  delay(120);
 +
 +  Wire.requestFrom(ADDR,​ 2); // 2byte every time
 +
 +  for (val=0; Wire.available()>​=1;​ ) {
 +    char c = Wire.read();​
 +    //​Serial.println(c,​ HEX);
 +    val = (val << 8) + (c & 0xFF);
 +  }
 +
 +  val = val / 1.2;
 +  lcd.clear();​
 +  lcd.setCursor(0,​ 0);
 +  lcd.print("​lx:​ ");
 +  lcd.setCursor(4,​ 0);
 +  lcd.println(val); ​
 +
 +  //​Serial.println("​OK"​);​
 +  digitalWrite(13,​ HIGH);
 +  delay(100); ​  
 +}
 +</​code>​
ocrobot/sensor_suite/bh1750/main.1560503132.txt.gz · 最后更改: 2019/06/14 09:05 由 董凯萍