bh1750_Example1.lua 673 B

123456789101112131415161718192021222324
  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. tmr.alarm(0, 10000, 1, function()
  10. SDA_PIN = 6 -- sda pin, GPIO12
  11. SCL_PIN = 5 -- scl pin, GPIO14
  12. bh1750 = require("bh1750")
  13. bh1750.init(SDA_PIN, SCL_PIN)
  14. bh1750.read(OSS)
  15. l = bh1750.getlux()
  16. print("lux: "..(l / 100).."."..(l % 100).." lx")
  17. -- release module
  18. bh1750 = nil
  19. package.loaded["bh1750"]=nil
  20. end)