Skip to content

Commit 35d1de6

Browse files
committed
Add PWMLED recipes
1 parent 0a5499d commit 35d1de6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/recipes.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,40 @@ Alternatively::
5959
:ref:`keep-your-script-running` for more information.
6060

6161

62+
LED with variable brightness
63+
============================
64+
65+
Any regular LED can have its brightness value set using PWM (pulse-width-modulation).
66+
In GPIO Zero, this can be achieved using :class:`PWMLED` using values between 0
67+
and 1::
68+
69+
from gpiozero import PWMLED
70+
from time import sleep
71+
72+
led = PWMLED(17)
73+
74+
while True:
75+
led.value = 0 # off
76+
sleep(1)
77+
led.value = 0.5 # half brightness
78+
sleep(1)
79+
led.value = 1 # full brightness
80+
sleep(1)
81+
82+
83+
Similarly to blinking on and off continuously, a PWMLED can pulse (fade in and
84+
out continuously)::
85+
86+
from gpiozero import PWMLED
87+
from signal import pause
88+
89+
led = PWMLED(17)
90+
91+
led.pulse()
92+
93+
pause()
94+
95+
6296
Button
6397
======
6498

0 commit comments

Comments
 (0)