nodemcu-firmware/lua_modules/bh1750/bh1750_Example1.lua

23 lines
627 B
Lua
Raw Permalink Normal View History

2015-01-30 14:24:54 +01:00
-- ***************************************************************************
-- BH1750 Example Program for ESP8266 with nodeMCU
-- BH1750 compatible tested 2015-1-30
--
-- Written by xiaohu
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
local bh1750 = require("bh1750")
2015-01-30 14:24:54 +01:00
local sda = 6 -- sda pin, GPIO12
local scl = 5 -- scl pin, GPIO14
2015-01-30 14:24:54 +01:00
do
bh1750.init(sda, scl)
2015-01-30 14:24:54 +01:00
tmr.create():alarm(10000, tmr.ALARM_AUTO, function()
bh1750.read()
local l = bh1750.getlux()
print("lux: "..(l / 100).."."..(l % 100).." lx")
end)
end