Raspberry Pico PWM signal
13/02/2021 | Views: 398 | Arduino | by: ELECTRONOOBS      

PWM signal code

Finally, I have one more example. The PWM control. Remember that we have 16 pins that could create PWM signal. In the code we import pin and PWM from machine module. I also import utime for crating delays. I attach the PWM to pin 25 which is the pin of the on-board LED. Set the frequency to 1000 Hz. With while true I create my infinite loop and inside here I create two more whiles that will increase and decrease the PWM value. With pwm.duty I write that value to the pin. And that’s it. I run this code and as you can see we can fade on and off the LED. Quite easy right? On the ocilloscope we can see the PWM signal increasing and decreasing at a constant frequency of 1Khz.

# Example using PWM to fade an LED.
import utime
from machine import Pin, PWM

PWM_width = 0

# Construct PWM object, with LED on Pin(25).
pwm = PWM(Pin(25))

# Set the PWM frequency to 1Khz.

while True:  
  while PWM_width < 65536:
      PWM_width += 10
  while PWM_width > 0:
      PWM_width -= 10

micropython PWM signal raspberry pi PICO

13/02/2021 | Views: 398 | Arduino | by: ELECTRONOOBS      

Last tutorials

Escaperoom Puzzle
Raspberry Pi PICO i2c OLED example
Raspberry Pi PICO ADC + Temperature Example
Upload permanent code to Raspberry Pi PICO
Raspberry Pi PICO LED blink Example



PCBWAY PCB service

PCBWAY PCB service

Arduino curso en español desde cero