From 35d1de644b9d4daa16593bf3542c7a5bf9de75ae Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Fri, 27 May 2016 00:01:48 +0100 Subject: [PATCH] Add PWMLED recipes --- docs/recipes.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/recipes.rst b/docs/recipes.rst index 7ea0f06..4d3b8bc 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -59,6 +59,40 @@ Alternatively:: :ref:`keep-your-script-running` for more information. +LED with variable brightness +============================ + +Any regular LED can have its brightness value set using PWM (pulse-width-modulation). +In GPIO Zero, this can be achieved using :class:`PWMLED` using values between 0 +and 1:: + + from gpiozero import PWMLED + from time import sleep + + led = PWMLED(17) + + while True: + led.value = 0 # off + sleep(1) + led.value = 0.5 # half brightness + sleep(1) + led.value = 1 # full brightness + sleep(1) + + +Similarly to blinking on and off continuously, a PWMLED can pulse (fade in and +out continuously):: + + from gpiozero import PWMLED + from signal import pause + + led = PWMLED(17) + + led.pulse() + + pause() + + Button ======