+ Add ds18b20.EN.md. Translating, and haven't finished.
This commit is contained in:
parent
d8e7fc777e
commit
aae17e54d7
|
@ -0,0 +1,139 @@
|
|||
#DS18B20 Module
|
||||
##Require
|
||||
|
||||
ds18b20 = require("ds18b20")
|
||||
|
||||
##Constant
|
||||
C, F, K
|
||||
|
||||
<a id="ds18b20_setup"></a>
|
||||
##setup()
|
||||
####Description
|
||||
Setting the pin of DS18B20.<br />
|
||||
|
||||
####Syntax
|
||||
setup(pin)
|
||||
|
||||
####Parameters
|
||||
pin: 1~10, IO index. If parameter is nil, it will use pin 9(GPIO2) automatically.<br />
|
||||
|
||||
####Returns
|
||||
nil
|
||||
|
||||
####Example
|
||||
```lua
|
||||
ds18b20 = require("ds18b20")
|
||||
ds18b20.setup(9)
|
||||
```
|
||||
|
||||
####See also
|
||||
**-** []()
|
||||
|
||||
|
||||
<a id="ds18b20_addrs"></a>
|
||||
## addrs()
|
||||
####Description
|
||||
Return all of the addresses table of DS18B20 on one-wire. 如果没有执行过setup(pin),则会自动对引脚9(GPIO2)进行单总线模式初始化。<br />
|
||||
|
||||
####Syntax
|
||||
addrs()
|
||||
|
||||
####Parameters
|
||||
nil
|
||||
####Returns
|
||||
addrs: 返回包含单总线上所有DS18B20器件的地址列表(table)。其中地址是字符串类型(String)。如果失败则返回nil. <br />
|
||||
|
||||
####Example
|
||||
```lua
|
||||
ds18b20 = require("ds18b20")
|
||||
ds18b20.setup(9)
|
||||
addrs = ds18b20.addrs()
|
||||
if (addrs ~= nil) then
|
||||
print("Total DS18B20 sensors: "..table.getn(addrs))
|
||||
end
|
||||
```
|
||||
|
||||
####See also
|
||||
**-** []()
|
||||
|
||||
|
||||
<a id="ds18b20_readNumber"></a>
|
||||
## readNumber()
|
||||
####Description
|
||||
读取温度数值。如果没有执行过setup(pin),则会自动对引脚9(GPIO2)进行单总线模式初始化。 <br />
|
||||
|
||||
####Syntax
|
||||
readNumber(addr, unit)
|
||||
|
||||
####Parameters
|
||||
addr: 字符串, DS18B20地址。 如果该Parameters为nil,会自动选择第一个发现的地址。<br />
|
||||
unit: 单位转换,只接受常量C(摄氏度),F(华氏度), K(开氏度)。如果该Parameters为nil,会自动选择常量C(摄氏度) 。<br />
|
||||
|
||||
####Returns
|
||||
t1: 数值,温度的整数部分。如果读取失败返回nil.<br />
|
||||
t2: 数值,温度的小数部分。如果读取失败返回nil.<br />
|
||||
|
||||
####Example
|
||||
```lua
|
||||
t=require("ds18b20")
|
||||
t.setup(9)
|
||||
addrs=t.addrs()
|
||||
-- Total DS18B20 numbers, assume it is 2
|
||||
print(table.getn(addrs))
|
||||
-- The first DS18B20
|
||||
print(t.readNumber(addrs[1],t.C))
|
||||
print(t.readNumber(addrs[1],t.F))
|
||||
print(t.readNumber(addrs[1],t.K))
|
||||
-- The second DS18B20
|
||||
print(t.readNumber(addrs[2],t.C))
|
||||
print(t.readNumber(addrs[2],t.F))
|
||||
print(t.readNumber(addrs[2],t.K))
|
||||
-- Just read
|
||||
print(t.readNumber())
|
||||
-- Just read as fahrenheit
|
||||
print(t.readNumber(nil,t.F))
|
||||
-- Read as values
|
||||
t1, t2 = t.readNumber()
|
||||
```
|
||||
####See also
|
||||
**-** []()
|
||||
|
||||
<a id="ds18b20_read"></a>
|
||||
## read()
|
||||
####Description
|
||||
读取温度字符串。如果没有执行过setup(pin),则会自动对引脚9(GPIO2)进行单总线模式初始化。 <br />
|
||||
|
||||
####Syntax
|
||||
read(addr, unit)
|
||||
|
||||
####Parameters
|
||||
addr: 字符串, DS18B20地址。 如果该Parameters为nil,会自动选择第一个发现的地址。<br />
|
||||
unit: 单位转换,只接受常量C(摄氏度),F(华氏度), K(开氏度)。如果该Parameters为nil,会自动选择常量C(摄氏度) 。<br />
|
||||
|
||||
####Returns
|
||||
t: 字符串,表示成字符串形式的温度。如果读取失败返回nil.<br />
|
||||
|
||||
####Example
|
||||
```lua
|
||||
t=require("ds18b20")
|
||||
t.setup(9)
|
||||
addrs=t.addrs()
|
||||
-- Total DS18B20 numbers, assume it is 2
|
||||
print(table.getn(addrs))
|
||||
-- The first DS18B20
|
||||
print(t.read(addrs[1],t.C))
|
||||
print(t.read(addrs[1],t.F))
|
||||
print(t.read(addrs[1],t.K))
|
||||
-- The second DS18B20
|
||||
print(t.read(addrs[2],t.C))
|
||||
print(t.read(addrs[2],t.F))
|
||||
print(t.read(addrs[2],t.K))
|
||||
-- Just read
|
||||
print(t.read())
|
||||
-- Just read as centigrade
|
||||
print(t.read(nil,t.C))
|
||||
|
||||
```
|
||||
####See also
|
||||
**-** []()
|
||||
|
Loading…
Reference in New Issue