nodemcu-firmware/lua_modules/bh1750/bh1750_EN.md

1.4 KiB

bh1750 Module

##Require

bh1750 = require("bh1750")

Release

bh1750 = nil
package.loaded["bh1750"]=nil

##init() ####Description Setting the I2C pin of bh1750.

####Syntax init(sda, scl)

####Parameters sda: 1~12, IO index.
scl: 1~12, IO index.

####Returns nil

####Example

SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14

bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)

-- release module
bh1750 = nil
package.loaded["bh1750"]=nil

####See also -

##read() ####Description Read Lux data from bh1750.

####Syntax read()

####Parameters nil.

####Returns nil.

####Example

SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14

bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read()

-- release module
bh1750 = nil
package.loaded["bh1750"]=nil

####See also -

##getlux() ####Description Get lux from bh1750.

####Syntax getlux()

####Parameters nil.

####Returns l: Integer, getlux from bh1750.

####Example

SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14

bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read()
l = bh1750.getlux()
print("lux: "..(l / 100).."."..(l % 100).." lx")

-- release module
bh1750 = nil
package.loaded["bh1750"]=nil

####See also -