bh1750_Example1.lua 627 B

12345678910111213141516171819202122
  1. -- ***************************************************************************
  2. -- BH1750 Example Program for ESP8266 with nodeMCU
  3. -- BH1750 compatible tested 2015-1-30
  4. --
  5. -- Written by xiaohu
  6. --
  7. -- MIT license, http://opensource.org/licenses/MIT
  8. -- ***************************************************************************
  9. local bh1750 = require("bh1750")
  10. local sda = 6 -- sda pin, GPIO12
  11. local scl = 5 -- scl pin, GPIO14
  12. do
  13. bh1750.init(sda, scl)
  14. tmr.create():alarm(10000, tmr.ALARM_AUTO, function()
  15. bh1750.read()
  16. local l = bh1750.getlux()
  17. print("lux: "..(l / 100).."."..(l % 100).." lx")
  18. end)
  19. end