koding fun

Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 640|回復: 2

請教各位大大2個Bh1750

[複製鏈接]
發表於 2018-5-23 19:35:13 來自手機 | 顯示全部樓層 |閱讀模式
我接了2個Bh1750打算做追光感測器
但是輸出結果卻是2個一樣的值
程式碼:
/*

  Example of BH1750 library usage.

  This example initialises the BH1750 object using the default high resolution
  continuous mode and then makes a light level reading every second.

  Connection:

    VCC -> 3V3 or 5V
    GND -> GND
    SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
    SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
    ADD -> (not connected) or GND

  ADD pin is used to set sensor I2C address. If it has voltage greater or equal to
  0.7VCC voltage (e.g. you've connected it to VCC) the sensor address will be
  0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will
  be 0x23 (by default).

*/

#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;
BH1750 LightSensor;

void setup(){

  Serial.begin(9600);

  // Initialize the I2C bus (BH1750 library doesn't do this automatically)
  Wire.begin();
  // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);

  lightMeter.begin();
  LightSensor.begin();
  Serial.println(F("BH1750 Test begin"));

}


void loop() {

  uint16_t lux = lightMeter.readLightLevel();
  uint16_t lux2 = LightSensor.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(100);
   Serial.print("Light: ");
  Serial.print(lux2);
  Serial.println(" lx");
  delay(1000);
}
請問下要如何修改
小弟剛接觸程式語言請大大教我下
發表於 2018-5-23 20:11:05 | 顯示全部樓層
如果要接兩個1750
必須要把其中一個的位址設成不一樣,
也就是
1. 其中一顆的 ADDR 接到 vcc
     另一個不改
2.把
BH1750 LightSensor;
改成
BH1750 LightSensor(0x5c);
 樓主| 發表於 2018-5-24 07:01:32 來自手機 | 顯示全部樓層
好謝謝我試試看
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2020-8-12 15:09 , Processed in 0.061594 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表