sine 发表于 2015-7-19 23:09:23

GY-30学习资料

转载声明:本博文章若无特别说明,皆为原创,转载请以链接形式标明本文地址。谢谢!;)

本文链接:http://fzblog.sinaapp.com/2013/05/07/159.html
/*****************转发别人的资料********************/
/*
BH1750光照度传感器程序代码
Version 1.0
作者:王俊锋泽
博客:http://www.xn--7tqt52e1pef42b.cn/

https://github.com/hackwjfz/Arduino/blob/master/bh1750.ino

接法:
VCC-5v
GND-GND
SCL-SCL(A5)
SDA-SDA(A4)
ADD-GND
*/
#include <Wire.h>
#include <math.h>
int BH1750address = 0x23;//BH1750 I2C地址
byte buff;
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Serial.print( BH1750() );
Serial.println("");
}
double BH1750() //BH1750设备操作
{
int i=0;
double val=0;
//开始I2C读写操作
Wire.beginTransmission(BH1750address);
Wire.write(0x10);//1lx reolution 120ms//发送命令
Wire.endTransmission();
delay(200);
//读取数据
Wire.beginTransmission(BH1750address);
Wire.requestFrom(BH1750address, 2);
while(Wire.available()) //
{
buff = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
if(2==i)
{
val=((buff<<8)|buff)/1.2;
}
return val;
}
页: [1]
查看完整版本: GY-30学习资料