Example: 50-OpenMV-Boards/52-Alif-Boards/50-Board-Control/pwm_control.py

# 本作品采用MIT许可证授权。
# Copyright (c) 2013-2026 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# PWM 控制示例
#
# This example shows how to do PWM with your OpenMV Cam.

import time
from machine import PWM

# P0 and P1 share the same UTIMER channel so they need
# 具有相同的频率。
p0 = PWM("P0", freq=100, duty_u16=32768)
p1 = PWM("P1", freq=100, duty_u16=32768)

# P2 and P3 share the same UTIMER channel so they need
# 具有相同的频率。
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 ""