1624 views|1 replies

1w

Posts

25

Resources
The OP
 

[SAMR21 New Gameplay] 22. PWM [Copy link]

 

The PWM function is in the pulseio module. It is also very easy to use, such as:

import pulseio
import board

pwm = pulseio.PWMOut(board.D13, frequency=50)
pwm.duty_cycle = 2 ** 15


The duty cycle of the PWM output can be adjusted through the duty_cycle parameter, which ranges from 0 to 65535.



This content is originally created by dcexpert , a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

 
 

1w

Posts

25

Resources
2
 

On SAMR21, we can use the PWM function to make a breathing light:

import time
import pulseio
from microcontroller import pin

pwm = pulseio.PWMOut(pin.PA19)
n = 0

while 1:
    pwm.duty_cycle = abs(65535 - n*4096)
    n = (n + 1)%32
    time.sleep(0.05)

The changing algorithm of the breathing light is different from before and is simpler now.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list