【无标题】测试pwm在jetsonnano中

import time
import Jetson.GPIO as GPIO

配置 GPIO 针脚

pin_pwm = 33
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin_pwm, GPIO.OUT)

定义一个简单的 PWM 简单循环

def simple_pwm(pin, frequency, duty_cycle, duration):
T = 1.0 / frequency
T_high = T * duty_cycle
T_low = T - T_high
start_time = time.time()

while (time.time() - start_time) < duration:
    GPIO.output(pin, GPIO.HIGH)
    time.sleep(T_high)
    GPIO.output(pin, GPIO.LOW)
    time.sleep(T_low)

测试 PWM

try:
while True:
simple_pwm(pin_pwm, frequency=50, duty_cycle=0.5, duration=5)
time.sleep(0.1)

finally:
GPIO.cleanup()

你可能感兴趣的:(python,matlab,百度,twitter)