zephyr/samples/basic/fade_led
Luca Burelli 187a8ad09b samples: fade_led: fix build error when PWM is not enabled
Some boards may define LEDs but disable them by default due to conflicts
with other peripherals. In this case, the new sample code introduced in
a5fd92b ("samples: fade_led: use all available LEDs") fails to build
with a missing symbol error.

Fix this by checking if the PWM device (the parent of the LED alias) is
enabled before using it. This implicitly discards invalid aliases.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-06 14:47:15 +01:00
..
boards samples: basic: add support for nRF54H20 cpuppr PWM 2025-01-31 09:38:25 +01:00
src samples: fade_led: fix build error when PWM is not enabled 2025-02-06 14:47:15 +01:00
sysbuild/vpr_launcher samples: basic: add support for nRF54H20 cpuppr PWM 2025-01-31 09:38:25 +01:00
CMakeLists.txt
prj.conf
README.rst hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
sample.yaml samples: basic: fade_led: add testing base on console output 2024-06-05 04:24:22 -07:00

.. zephyr:code-sample:: fade-led
   :name: Fade LED
   :relevant-api: pwm_interface

   Fade an LED using the PWM API.

Overview
********

This application "fades" a LED using the :ref:`PWM API <pwm_api>`.

The LED starts off increases its brightness until it is fully or nearly fully
on. The brightness then decreases until the LED is off, completing on fade
cycle. Each cycle takes 2.5 seconds, and the cycles repeat forever. The PWM
period is taken from Devicetree. It should be fast enough to be above the
flicker fusion threshold.

Requirements and Wiring
***********************

This sample has the same requirements and wiring considerations as the
:zephyr:code-sample:`pwm-blinky` sample.

Building and Running
********************

To build and flash this sample for the :ref:`nrf52840dk_nrf52840`:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/fade_led
   :board: nrf52840dk/nrf52840
   :goals: build flash
   :compact:

Change ``nrf52840dk/nrf52840`` appropriately for other supported boards.

After flashing, the sample starts fading the LED as described above. It also
prints information to the board's console.