Example: 50-OpenMV-Boards/53-N6-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

# P7 and P8 share TIM4 so they need to have the same frequency.
p7 = PWM("P7", freq=50, duty_ns=(2000 * 1000))
p8 = PWM("P8", freq=50, duty_ns=(2000 * 1000))

# P9 (TIM17) and P10 (TIM15) each use their own timer.
p9 = PWM("P9", freq=50, duty_ns=(2000 * 1000))
p10 = PWM("P10", freq=50, duty_ns=(2000 * 1000))


while True:
    for i in range(1000, 2000, 100):
        p7.duty_ns(i * 1000)
        p8.duty_ns(i * 1000)
        p9.duty_ns(i * 1000)
        p10.duty_ns(i * 1000)
        time.sleep_ms(1000)

    for i in range(2000, 1000, -100):
        p7.duty_ns(i * 1000)
        p8.duty_ns(i * 1000)
        p9.duty_ns(i * 1000)
        p10.duty_ns(i * 1000)
        time.sleep_ms(1000)

results matching ""

    No results matching ""