气体浓度传感器

python 编程:

创建实例

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

方法

  • get_gas_ratio()
    获取传感器检测到的气体浓度,气体浓度范围为: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

g3 = thunbot.gas(thunbot.PORT_3)

print("normal test")
for i in range(0,20):
  print(g3.get_gas_ratio())
  time.sleep(1)

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

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

results matching ""

    No results matching ""