devicescript icon indicating copy to clipboard operation
devicescript copied to clipboard

Can devicescript use PWM?

Open ken1691 opened this issue 1 year ago • 0 comments

Can devicescript use PWM? For example, micropython does this:

from machine import Pin, PWM
import time

# 配置PWM引脚
ir_pin = Pin(14, Pin.OUT)
pwm = PWM(ir_pin, freq=36000)  # 设置载波频率为36KHz

# 发送一个简单的红外信号
def send_ir_signal():
    pwm.duty(512)  # 设置占空比,50%占空比
    time.sleep_ms(100)  # 发送100ms的信号
    pwm.duty(0)  # 关闭信号
    time.sleep_ms(100)  # 间隔100ms

# 主循环
while True:
    send_ir_signal()
    time.sleep(1)  # 每秒发送一次

ken1691 avatar Oct 17 '24 16:10 ken1691