pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

PWM

案例程序

初始化引脚的方向,并获取引脚的值打印在屏幕上

from m5stack import *
from m5stack_ui import *
from uiflow import *
import machine
import time


screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)

i = None

label0 = M5Label('label0', x=137, y=88, color=0x000, font=FONT_MONT_14, parent=None)

PWM0 = machine.PWM(26, freq=50, duty=3, timer=0)
while True:
  for i in range(13):
    PWM0.duty(i)
    wait_ms(1000)
    label0.set_text(str(i))
  wait_ms(2)

功能说明

machine.PWM(26, freq=10000, duty=50, timer=0)
  • 设置产生PWM信号的引脚、频率、占空比、和计时器选择
PWM0.freq(1)
  • 设置PWM产生频率
PWM0.duty(0)
  • 设置PWM占空比
PWM0.pause()
  • 暂停PWM信号产生
PWM0.resume() 
  • 继续pwm信号的产生
PWM0.hold_us(0)
  • 保持住PWM信号几us(毫秒)
On This Page