土壤湿度传感器

python 编程:

创建实例

  • soil(port_num)
    创建soil实例,port_num 可取值为 thunbot.PORT_1, thunbot.PORT_2,thunbot.PORT_3, thunbot.PORT_4,thunbot.PORT_A,thunbot.PORT_B

方法

  • get_humidity()
    获取传感器检测到的土壤湿度,土壤湿度范围为:0 ~ 100。

  • set_extremum(opt_type,opt_data)
    设置传感器的最小值、最大值及复位

opt_type 取值 功能
SET_MINIMUM 设置最小值
SET_MAXIMUM 设置最大值
RESET 复位,恢复默认值

opt_data 的取值范围为:0 ~ 100。

注:opt_data的值在RESET时,不可填写

编程示范


import thunbot
import time

s3 = thunbot.soil(thunbot.PORT_3)

print("normal test")
s3.set_extremum(s3.RESET)
for i in range(0,20):
  print(s3.get_humidity())
  time.sleep(1)

print("mode test")
s3.set_extremum(s3.SET_MAXIMUM,60) 
s3.set_extremum(s3.SET_MINIMUM,30) 
for i in range(0,20):
  print(s3.get_humidity())
  time.sleep(1)

print("reset test")
s3.set_extremum(s3.RESET)  
for i in range(0,20):
  print(s3.get_humidity())
  time.sleep(1)

results matching ""

    No results matching ""