コード例 #1
0
 def initPWM(pin):
     """ Sets a pin to PWM """
     pwm = PWM(pin, 0)
     pwm.frequency = 1e3
     pwm.duty_cycle = 0
     pwm.enable()
     return pwm
コード例 #2
0
 def initPWM(pin):
     pwm = PWM(pin, 0)
     pwm.frequency = 1e3
     pwm.duty_cycle = 0
     pwm.enable()
     return pwm
コード例 #3
0
print(mode)

# Open PWM channel 0, pin 32
pins = range(0, 41)
"""
for pin in pins:
	try:
		pwm = PWM(0, pin)
		print("** Channel 0 pin {} works!".format(pin))
	except:
		print("Pin {} does not work".format(pin))
"""
pwm = PWM(0, 2)
pwm = PWM(0, 0)

#Channel 0 pin 2

# Set frequency to 1 kHz
pwm.frequency = 2e3
# Set duty cycle to 75%
pwm.duty_cycle = 0.25

pwm.enable()

# Change duty cycle to 50%
pwm.duty_cycle = 0.25

time.sleep(5 * 60)

pwm.close()
コード例 #4
0
"""periphery库 PWM测试."""
import time
from periphery import PWM

# 打开 PWM 3, channel 0 ,对应开发板上PWM3外设

try:
    pwm = PWM(2, 0)
    # 设置PWM输出频率为 1 kHz
    pwm.frequency = 1e3
    # 设置占空比为 50%
    pwm.duty_cycle = 0.50
    # 开启PWM输出
    pwm.enable()
    while True:
        for i in range(0, 9):
            time.sleep(0.1)
            pwm.duty_cycle += 0.05
        for i in range(0, 9):
            time.sleep(0.1)
            pwm.duty_cycle -= 0.05
        if pwm.duty_cycle == 0.0:
            time.sleep(1)
finally:
    pwm.close()