pwm_control.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2026 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# PWM 控制示例
#
# 此示例展示了如何在OpenMV摄像头上使用PWM。

import time
from machine import PWM

# P0和P1共享同一个UTIMER通道,因此它们需要
# 具有相同的频率。
p0 = PWM("P0", freq=100, duty_u16=32768)
p1 = PWM("P1", freq=100, duty_u16=32768)

# P2和P3共享同一个UTIMER通道,因此它们需要
# 具有相同的频率。
p2 = PWM("P2", freq=100, duty_u16=32768)
p3 = PWM("P3", freq=100, duty_u16=32768)

while True:
    for i in range(0, 65536, 256):
        p0.duty_u16(65535 - i)
        time.sleep_ms(10)
    p0.duty_u16(32768)

    for i in range(0, 65536, 256):
        p1.duty_u16(65535 - i)
        time.sleep_ms(10)
    p1.duty_u16(32768)

    for i in range(0, 65536, 256):
        p2.duty_u16(65535 - i)
        time.sleep_ms(10)
    p2.duty_u16(32768)

    for i in range(0, 65536, 256):
        p3.duty_u16(65535 - i)
        time.sleep_ms(10)
    p3.duty_u16(32768)

results matching ""

    No results matching ""