Advertisement
belrey10

Day 8: Advanced Control – Pulse Width Modulation (PWM)

Nov 5th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. from machine import Pin, PWM
  2. import time
  3.  
  4. # Initialize the LED pin for PWM
  5. led = PWM(Pin(15))
  6. led.freq(1000)
  7.  
  8. while True:
  9.     for duty_cycle in range(0, 1024):
  10.         led.duty_u16(duty_cycle)
  11.         time.sleep(0.005)
  12.     for duty_cycle in range(1023, -1, -1):
  13.         led.duty_u16(duty_cycle)
  14.         time.sleep(0.005)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement