触碰传感器

python 编程:

创建实例

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

方法

  • get_event()
    获取触碰传感器时间,返回值为,0:未按下状态(释放状态) 1:按下状态 2:按下后释放(触碰)

  • set_rgb(red, green, blue)
    设置触碰模块RGB灯颜色,范围为: 0 ~ 255

  • reset_rgb()
    复位灯光模式:自动模式,释放状态亮绿灯,按下状态亮红灯

编程示范


import thunbot
import time

t3 = thunbot.touch(thunbot.PORT_3)

print("get_event")
for i in range(0,20):
  print(t3.get_event())
  time.sleep(1)

print("set_rgb")
t3.set_rgb(255,0,0)
for i in range(0,20):
  print(t3.get_event())
  time.sleep(1)

print("reset_rgb")
t3.reset_rgb()

for i in range(0,20):
  print(t3.get_event())
  time.sleep(1)

results matching ""

    No results matching ""