nRF5 SDK v17.1.0
LED softblink library

The LED softblink library provides functions to generate and configure a changing pulse-width modulated output signal that can be used to smoothly blink LEDs.

The library uses the Low-power PWM library to generate the signal.

Key features include:

Only one instance of LED softblink can be used at a time. If you require more instances, use the Low-power PWM library directly.

This library uses an application timer and is therefore not very accurate. It can be used to control LEDs, but for peripherals that need a high accuracy, you should use the PWM library instead.

Starting LED softblink

Complete the following steps to start LED softblink on the default LEDs:

  1. Start Application Timer.
  2. Create a led_sb_init_params_t structure that holds the initialization parameters. If you want to use the default configuration, call the LED_SB_INIT_DEFAULT_PARAMS macro with the LED mask to fill the init structure.
    The following parameters must be specified:
    • active_high: Polarity.
    • duty_cycle_max: Maximum pulse width (in ticks, with the period set to 255 ticks).
    • duty_cycle_min: Minimum pulse width (in ticks, with the period set to 255 ticks).
    • duty_cycle_step: Duty cycle change step. This value denotes the delta in ticks between the current duty cycle and the next.
    • off_time_ms: Time to stay in minimum duty cycle.
    • on_time_ms: Time to stay in maximum duty cycle.
    • leds_pin_bm: Mask of used LEDs.
  3. Call led_softblink_init with the init structure to initialize LED softblink.
  4. Use the led_softblink_start function to start LED softblink. Specify the same pin mask that you used in led_sb_init_params_t or a subset of it.

The following code example shows how to initialize LED softblink with the default configuration and start blinking the LEDs:

led_sb_init_params_t led_sb_init_params = LED_SB_INIT_DEFAULT_PARAMS(LEDS_MASK); // create structure and fill with default configuration using given LEDS_MASK
ret_code_t ret = led_softblink_init(&led_sb_init_params);
// handle ret - if (ret==NRF_SUCCESS):
ret = led_softblink_start(LEDS_MASK);

As a result, the LEDs should start blinking smoothly.

Example

See the LED Softblink Example for a full application that uses the LED softblink library.

Usage with a SoftDevice

LED softblink uses RTC. Therefore, it is less accurate when used with a SoftDevice.


Documentation feedback | Developer Zone | Subscribe | Updated