How to make led blinking only 5 times?

Hi,

I'm using the GPIO mode of CAF leds module to control led.

LED_EFFECT_LED_BLINK or LED_EFFECT_LED_BLINK2 macro can be used to set the effects of led. But the loop_forever which is a member in led_effect are all set to true, you can look here: https://github.com/nrfconnect/sdk-nrf/blob/main/include/caf/led_effect.h#L193

It means that it will blinking forever, so how can I make led blinking only 5 times?

Parents
  • Hi

    Can you provide some more information on what your end goal is here, as using the CAF module will be an over-complication if all you want to do is to blink a led 5 times. The Blinky demo in Zephyr should be more than sufficient if you only need the Blinky functionality.

    If you need to use the CAF module, I think the best way to go about this would be to make a copy of this LED_BLINK2 function and disable the loop_forever and instead set it to blink 5 times, and then call that function instead of the LED_EFFECT_LED_BLINK2.

    Best regards,

    Simon

Reply
  • Hi

    Can you provide some more information on what your end goal is here, as using the CAF module will be an over-complication if all you want to do is to blink a led 5 times. The Blinky demo in Zephyr should be more than sufficient if you only need the Blinky functionality.

    If you need to use the CAF module, I think the best way to go about this would be to make a copy of this LED_BLINK2 function and disable the loop_forever and instead set it to blink 5 times, and then call that function instead of the LED_EFFECT_LED_BLINK2.

    Best regards,

    Simon

Children
  • Thanks,

    I am not quite sure when the CAF LED module is used, but maybe it is necessary to allow the user to customize the number of blink, because low-power products don't blink all the time, just a suggestion.

    I tried to change the LED_EFFECT_LED_BLINK2, if I want to blink 5 times, I need to add five structures of led_effect_step such as below. It gets more complicated if you have more flashes.

    #define LED_EFFECT_LED_BLINK3(_period_on, _period_off, _color) \
        {                                                          \
            .steps      = ((const struct led_effect_step[]){       \
                {                                             \
                         .color         = _color,                  \
                         .substep_count = 1,                       \
                         .substep_time  = (_period_off ),           \
                },                                            \
                {                                             \
                         .color         = LED_NOCOLOR(),           \
                         .substep_count = 1,                       \
                         .substep_time  = ( _period_on),            \
                },                                            \
                {                                             \
                         .color         = _color,                  \
                         .substep_count = 1,                       \
                         .substep_time  = (_period_off ),           \
                },                                            \
                {                                             \
                         .color         = LED_NOCOLOR(),           \
                         .substep_count = 1,                       \
                         .substep_time  = ( _period_on),            \
                },                                            \
                {                                             \
                         .color         = _color,                  \
                         .substep_count = 1,                       \
                         .substep_time  = (_period_off ),           \
                },                                            \
                {                                             \
                         .color         = LED_NOCOLOR(),           \
                         .substep_count = 1,                       \
                         .substep_time  = ( _period_on),            \
                },                                            \
                {                                             \
                         .color         = _color,                  \
                         .substep_count = 1,                       \
                         .substep_time  = (_period_off ),           \
                },                                            \
                {                                             \
                         .color         = LED_NOCOLOR(),           \
                         .substep_count = 1,                       \
                         .substep_time  = ( _period_on),            \
                },                                            \
                {                                             \
                         .color         = _color,                  \
                         .substep_count = 1,                       \
                         .substep_time  = (_period_off ),           \
                },                                            \
                {                                             \
                         .color         = LED_NOCOLOR(),           \
                         .substep_count = 1,                       \
                         .substep_time  = ( _period_on),            \
                },                                            \
            }),                                               \
            .step_count = 10, .loop_forever = false,                 \
        }

Related