ir
--- 板载红外收发¶
ir
模块的主要功能与函数
功能相关函数¶
-
ir.
receive
()¶ 返回红外收到的字符串信息,所以发送端发送的数据必须以
\n
结束。 如果是接收 NEC编码协议的遥控器指令,请使用另外一个函数receive_remote_code()
。
-
ir.
receive_remote_code
()¶ 获取红外遥控器数据,红外遥控器数据包含地址和内容两部分,因此返回一个长度为2的list数据。 前面一个参数是地址码,后面一个参数是数据码。
-
ir.
send
(str)¶ 发送红外字符串,参数:
- str 要发射的字符串数据,
send
函数会在字符串末尾自动加入\n
结束符。
- str 要发射的字符串数据,
-
ir.
start_learning
()¶ 开始红外学习,仅支持学习标准NEC协议的遥控器指令。
-
ir.
stop_learning
()¶ 停止红外学习
-
ir.
save_learned_result
(index)¶ 将学习的红外编码结果保存到相应区域,参数:
- index 数值范围是
0 ~ 15
,一共有16个存储区域。
- index 数值范围是
-
ir.
send_learned_result
(index = 1)¶ 发送红外学习保存下来的红外编码, 默认发送 index = 1的区域的学习结果,参数:
- index 数值范围是
0 ~ 15
,一共有16个存储区域。
- index 数值范围是
-
ir.
learn
(time = 3)¶ 红外学习
time
秒,在调用该API后会保存time
秒内学到的红外信息。 默认会保留到index = 1的区域,参数:- time 学习时间,单位是
秒
。
- time 学习时间,单位是
程序示例1:¶
import codey
import event
@event.start
def start_cb():
print("start event succeeded")
while True:
codey.display.show(codey.ir.receive_remote_code()[1])
程序示例2:¶
import codey
import event
@event.button_a_pressed
def button_a_cb():
print("button a event succeeded")
codey.ir.learn()
codey.led.show(0, 100, 0)
@event.button_b_pressed
def button_a_cb():
print("button b event succeeded")
while True:
codey.ir.send_learned_result()
@event.button_c_pressed
def button_c_cb():
print("button b event succeeded")
while True:
codey.display.show(codey.ir.receive())