diff --git a/samples/drivers/led/pwm/README.rst b/samples/drivers/led/pwm/README.rst index 62e830fcae17..caecb6c34130 100644 --- a/samples/drivers/led/pwm/README.rst +++ b/samples/drivers/led/pwm/README.rst @@ -20,6 +20,7 @@ For each PWM LEDs (one after the other): - Turning on - Turning off - Increasing brightness gradually +- Decreasing brightness gradually - Blinking on: 0.1 sec, off: 0.1 sec - Blinking on: 1 sec, off: 1 sec - Turning off diff --git a/samples/drivers/led/pwm/sample.yaml b/samples/drivers/led/pwm/sample.yaml index 21d27c0d6a99..8b7e745a292c 100644 --- a/samples/drivers/led/pwm/sample.yaml +++ b/samples/drivers/led/pwm/sample.yaml @@ -17,6 +17,7 @@ tests: - "Turned on" - "Turned off" - "Increasing brightness gradually" + - "Decreasing brightness gradually" - "Blinking on: ([0-9]+) msec, off: ([0-9]+) msec" - "(Blinking on: ([0-9]+) msec, off: ([0-9]+) msec|Cycle period not supported)" - "Turned off, loop end" diff --git a/samples/drivers/led/pwm/src/main.c b/samples/drivers/led/pwm/src/main.c index a59887c6b8f9..7ec77550defd 100644 --- a/samples/drivers/led/pwm/src/main.c +++ b/samples/drivers/led/pwm/src/main.c @@ -33,7 +33,7 @@ const int num_leds = ARRAY_SIZE(led_label); static void run_led_test(const struct device *led_pwm, uint8_t led) { int err; - uint16_t level; + int16_t level; LOG_INF("Testing LED %d - %s", led, led_label[led] ? : "no label"); @@ -67,6 +67,18 @@ static void run_led_test(const struct device *led_pwm, uint8_t led) } k_sleep(K_MSEC(1000)); + /* Decrease LED brightness gradually down to the minimum level. */ + LOG_INF(" Decreasing brightness gradually"); + for (level = MAX_BRIGHTNESS; level >= 0; level--) { + err = led_set_brightness(led_pwm, led, level); + if (err < 0) { + LOG_ERR("err=%d brightness=%d\n", err, level); + return; + } + k_sleep(K_MSEC(CONFIG_FADE_DELAY)); + } + k_sleep(K_MSEC(1000)); + #if CONFIG_BLINK_DELAY_SHORT > 0 /* Start LED blinking (short cycle) */ err = led_blink(led_pwm, led, CONFIG_BLINK_DELAY_SHORT, CONFIG_BLINK_DELAY_SHORT);