pwm_control.py

# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2023 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# PWM制御の例
#
# この例では、PWMの使用方法を示します。

import time
from pyb import Pin, Timer


class PWM:
    def __init__(self, pin, tim, ch):
        self.pin = pin
        self.tim = tim
        self.ch = ch


pwms = {
    "PWM1": PWM("D7", 3, 1),
    "PWM2": PWM("D8", 4, 3),
    "PWM3": PWM("D9", 4, 4),
}

# 以下のPWMで、デューティ比50%の1KHz矩形波を生成します。
for k, pwm in pwms.items():
    tim = Timer(pwm.tim, freq=1000)  # 周波数(Hz)
    ch = tim.channel(pwm.ch, Timer.PWM, pin=Pin(pwm.pin), pulse_width_percent=50)

while True:
    time.sleep_ms(1000)

results matching ""

    No results matching ""