pulseio – 支持基于单个脉冲的协议¶
该 pulseio模块包含提供对基本脉冲 IO 的访问的类。单个脉冲通常用于红外遥控器和 DHT 温度传感器。
如果程序在使用后继续,所有类都会更改硬件状态,并且在不再需要它们时应取消初始化。为此,请调用deinit() 或使用上下文管理器。有关更多信息,请参阅
Lifetime 和 ContextManagers for more info.
在这些板上可用
- 
class pulseio.PulseIn(pin: microcontroller.Pin, maxlen: int = 2, *, idle_state: bool = False)¶
- 测量一系列活动和空闲脉冲。这通常用于红外接收器和低成本温度传感器 (DHT)。脉冲信号由定时的活动和空闲周期组成。与 PWM 不同,活动和空闲对没有设置持续时间。 - 创建与给定引脚关联的 PulseIn 对象。该对象充当具有给定最大长度的只读脉冲长度序列。当它处于活动状态时,新的脉冲长度会添加到列表的末尾。当没有更多空间 (len() == - maxlen) 时,将删除最旧的脉冲长度以腾出空间。- 参数
 - 阅读一系列简短的脉冲: - import pulseio import board pulses = pulseio.PulseIn(board.D7) # Wait for an active pulse while len(pulses) == 0: pass # Pause while we do something with the pulses pulses.pause() # Print the pulses. pulses[0] is an active pulse unless the length # reached max length and idle pulses are recorded. print(pulses) # Clear the rest pulses.clear() # Resume with an 80 microsecond active pulse pulses.resume(80) - 
maxlen:int¶
- PulseIn 的最大长度。当 len() 等于 maxlen 时,不清楚哪些脉冲是活动的,哪些是空闲的。 
 - 
__exit__(self) → None¶
- 退出上下文时自动取消初始化硬件。有关更多信息,请参阅 Lifetime 和 ContextManagers。 
 
- 
class pulseio.PulseOut(pin: microcontroller.Pin, *, frequency: int = 38000, duty_cycle: int = 1 << 15)¶
- 打开和关闭脉冲 PWM“载波”输出。这通常用于红外遥控器。脉冲信号由定时开启和关闭周期组成。与 PWM 不同,开关对没有设定持续时间。 - 创建与给定引脚关联的 PulseOut 对象。 - 为了向后兼容, - pin可能是用作载体的 PWMOut 对象。此兼容性将在 CircuitPython 8.0.0 中删除。- 发送一系列短脉冲: - import array import pulseio import pwmio import board # 50% duty cycle at 38kHz. pwm = pulseio.PulseOut(board.D13, frequency=38000, duty_cycle=32768) # on off on off on pulses = array.array('H', [65000, 1000, 65000, 65000, 1000]) pulse.send(pulses) # Modify the array of pulses. pulses[0] = 200 pulse.send(pulses) - 
__exit__(self) → None¶
- 退出上下文时自动取消初始化硬件。有关更多信息,请参阅 Lifetime 和 ContextManagers 。 
 - 
send(self, pulses: _typing.ReadableBuffer) → None¶
- 从开启开始,以微秒为单位的脉冲交替开启和关闭持续时间。 对于无符号半字(两个字节), - pulses必须是- array.array数据类型为“H”的一个。- 此方法等待直到发送了整个脉冲阵列并确保之后信号关闭。 - Parameters
- 脉冲 (array.array) – 以微秒为单位的脉冲持续时间 
 
 
-