极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10692|回复: 0

GY-30学习资料

[复制链接]
发表于 2015-7-19 23:09:23 | 显示全部楼层 |阅读模式
转载声明:本博文章若无特别说明,皆为原创,转载请以链接形式标明本文地址。谢谢!;)

本文链接: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[2];
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Serial.print( BH1750() );
Serial.println("[lx]");
}
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[i] = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
if(2==i)
{
val=((buff[0]<<8)|buff[1])/1.2;
}
return val;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-16 07:03 , Processed in 0.034130 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表