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

# 本作品采用MIT许可证授权。
# Copyright (c) 2013-2026 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 舵机控制示例
#
# 本示例展示了如何利用OpenMV摄像头控制舵机。
#
# 舵机需要50 Hz的PWM,脉冲宽度为1000us到2000us。

import time
from machine import PWM

# P0 and P1 share the same UTIMER channel so they need
# 具有相同的频率。
p0 = PWM("P0", freq=50, duty_ns=(2000 * 1000))
p1 = PWM("P1", freq=50, duty_ns=(2000 * 1000))

# P2 and P3 share the same UTIMER channel so they need
# 具有相同的频率。
p2 = PWM("P2", freq=50, duty_ns=(2000 * 1000))
p3 = PWM("P3", freq=50, duty_ns=(2000 * 1000))


while True:
    for i in range(1000, 2000, 100):
        p0.duty_ns(i * 1000)
        p1.duty_ns(i * 1000)
        p2.duty_ns(i * 1000)
        p3.duty_ns(i * 1000)
        time.sleep_ms(1000)

    for i in range(2000, 1000, -100):
        p0.duty_ns(i * 1000)
        p1.duty_ns(i * 1000)
        p2.duty_ns(i * 1000)
        p3.duty_ns(i * 1000)
        time.sleep_ms(1000)

results matching ""

    No results matching ""