Skip to content

Commit b9544f9

Browse files
committed
example: Add ambientlight example using dh1750
Origin: https://github.com/tizenteam/node-i2c Forwarded: #99 Change-Id: I2ea802fa46de654d3c45acd667afefb7ff88da76 Signed-off-by: Philippe Coval <[email protected]>
1 parent 98e2301 commit b9544f9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-License: BSD-3-Clause-Attribution
2+
# Info: https://github.com/abandonware/bh1750
3+
4+
Wire = require '../../main'
5+
6+
GET = 0x10
7+
8+
9+
10+
class Ambientlight
11+
12+
address: 0x23
13+
14+
constructor: (@address) ->
15+
@wire = new Wire @address;
16+
17+
read: (callback) ->
18+
setTimeout =>
19+
@_read GET, 2, (err, buffer) ->
20+
if not err
21+
data = ((buffer[0] <<8) + buffer[1]) / 1.2;
22+
callback null, data
23+
else
24+
callback err, null
25+
, 200
26+
27+
_read: (cmd, length, callback) ->
28+
@wire.readBytes cmd, length, callback
29+
30+
sensor = new Ambientlight(0x23)
31+
sensor.read (err, data) ->
32+
console.log data
33+

0 commit comments

Comments
 (0)