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:
- Configurable intensity, pauses, and changing speed.
- Any number of output channels.
- Configurable polarity.
- Power efficient because of the use of the Low-power PWM library.
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:
- Start Application Timer.
- 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.
- Call led_softblink_init with the init structure to initialize LED softblink.
- 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:
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.