Created
May 22, 2017 10:42
-
-
Save maxpromer/c0fe8927074c5011f0a099b8f4f8fdb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#define BH1750_ADDR 0x23 | |
int readBH1750(byte dev_addr) { | |
Wire.beginTransmission(dev_addr); | |
Wire.write(0x10); | |
if (Wire.endTransmission() != 0) return -1; | |
delay(200); | |
Wire.requestFrom((int)dev_addr, 2); | |
return (Wire.available() >= 2) ? (Wire.read()<<8)|Wire.read() : -1; | |
} | |
void setup() { | |
Wire.begin(); | |
Serial.begin(9600); | |
} | |
void loop() { | |
Serial.print("Light is "); | |
Serial.print(readBH1750(BH1750_ADDR)); | |
Serial.println(" lx."); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment