Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
555d64af
Commit
555d64af
authored
Jan 30, 2015
by
Martin Han
Browse files
BH1750 Module, Written by xiaohu
parent
eb55edab
Changes
1
Hide whitespace changes
Inline
Side-by-side
lua_modules/bh1750/bh1750.lua
0 → 100644
View file @
555d64af
-- ***************************************************************************
-- BH1750 module for ESP8266 with nodeMCU
-- BH1750 compatible tested 2015-1-22
--
-- Written by xiaohu
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
local
moduleName
=
...
local
M
=
{}
_G
[
moduleName
]
=
M
--I2C slave address of GY-30
local
GY_30_address
=
0X23
-- i2c interface ID
local
id
=
0
--LUX
local
l
--CMD
local
CMD
=
0x10
local
init
=
false
function
M
.
init
(
sda
,
scl
)
i2c
.
setup
(
id
,
sda
,
scl
,
i2c
.
SLOW
)
--print("i2c ok..")
init
=
true
end
local
function
read_data
(
ADDR
,
commands
,
length
)
i2c
.
start
(
id
)
i2c
.
address
(
id
,
ADDR
,
i2c
.
TRANSMITTER
)
i2c
.
write
(
id
,
commands
)
i2c
.
stop
(
id
)
i2c
.
start
(
id
)
i2c
.
address
(
id
,
ADDR
,
i2c
.
RECEIVER
)
tmr
.
delay
(
200000
)
c
=
i2c
.
read
(
id
,
length
)
i2c
.
stop
(
id
)
return
c
end
local
function
read_lux
()
dataT
=
read_data
(
GY_30_address
,
CMD
,
2
)
UT
=
string.byte
(
dataT
,
1
)
*
256
+
string.byte
(
dataT
,
2
)
l
=
(
UT
*
1000
/
12
)
return
(
l
)
end
function
M
.
read
()
if
(
not
init
)
then
print
(
"init() must be called before read."
)
else
read_lux
()
end
end
function
M
.
getlux
()
return
l
end
return
M
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment