-
Notifications
You must be signed in to change notification settings - Fork 0
/
led-pwm.py
35 lines (30 loc) · 909 Bytes
/
led-pwm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#-----------------------------------------------------------------------------#
# LED Brightness control with Pulse Width Modulation
#
# Micropython code for Raspberry Pi Pico w
#
# File : led-pwm.py
# Source : https://github.com/RPiSpy/pi-pico
#
# Desc : Cycle the brightness of an LED using PWM
# Hardware : Pi Pico or Pi Pico W
# LED
# LED & resistor (56-330 ohm)
# Software : n/a
#
# Author : Matt Hawkins
# Website : https://www.raspberrypi-spy.co.uk/
#-----------------------------------------------------------------------------#
import time
from machine import Pin,PWM
pwm = PWM(Pin(15))
pwm.freq(1000)
while True:
# Loop brightness from min to max
for duty in range(65535):
pwm.duty_u16(duty)
time.sleep_us(5)
# Loop brightness from max to min
for duty in range(65025, 0, -1):
pwm.duty_u16(duty)
time.sleep_us(5)