Skip to content

Commit ff2debf

Browse files
committed
add BH1750 Sensor
1 parent d63f1a5 commit ff2debf

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Raspberry.IO.InterIntegratedCircuit;
2+
using Raspberry.Timers;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Raspberry.IO.Components.Sensors.Light
9+
{
10+
namespace RPI.Sensor.Sensors.Light
11+
{
12+
public class BH1750Connection
13+
{
14+
public I2cDeviceConnection Connection { get; set; }
15+
public BH1750Connection(I2cDeviceConnection connection)
16+
{
17+
Connection = connection;
18+
}
19+
20+
public void SetOff()
21+
{
22+
Connection.Write(0x00);
23+
}
24+
public void SetOn()
25+
{
26+
Connection.Write(0x01);
27+
}
28+
public void Reset()
29+
{
30+
Connection.Write(0x07);
31+
}
32+
33+
public double GetData()
34+
{
35+
Connection.Write(0x10);
36+
HighResolutionTimer.Sleep(TimeSpanUtility.FromMicroseconds(150 * 1000));
37+
byte[] readBuf = Connection.Read(2);
38+
39+
var valf = readBuf[0] << 8;
40+
valf |= readBuf[1];
41+
return valf / 1.2 * (69 / 69) / 1;
42+
43+
// var valf = ((readBuf[0] << 8) | readBuf[1]) / 1.2;
44+
// return valf;
45+
46+
// return Math.Round(valf / (2 * 1.2), 2);
47+
48+
}
49+
50+
}
51+
}
52+
53+
}

0 commit comments

Comments
 (0)