示例#1
0
from machine import Timer, PWM
import time
from board import board_info
from fpioa_manager import fm

tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM)
ch0 = PWM(tim, freq=3000000, duty=20, pin=board_info.LED_G, enable=False)
ch0.enable()
time.sleep(3)
ch0.freq(2000000)
print("freq:", ch0.freq())
ch0.duty(60)
time.sleep(3)
ch0.disable()
示例#2
0
from fpioa_manager import *
from Maix import GPIO
import utime

fm.register(34, fm.fpioa.GPIO0)
tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM)
ch = PWM(tim, freq=440, duty=1, pin=34)

freq = 0
loop = 0
dir = True

while True:
    if dir:
        freq += 1
    else:
        freq -= 1

    if freq > 440:
        frew = 440
        dir = False
    elif freq < 262:
        freq = 262
        dir = True
        loop += 1

    time.sleep(0.01)
    ch.freq(freq)
    if loop > 1:
        ch.disable()