Skip to content

Commit

Permalink
samples: led: pwm: add decreasing brightness logic
Browse files Browse the repository at this point in the history
Add a decreasing brightness phase to the sample's logic.

Signed-off-by: Yishai Jaffe <[email protected]>
  • Loading branch information
yishai1999 authored and kartben committed Dec 17, 2024
1 parent 7260f2d commit a75ed26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions samples/drivers/led/pwm/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions samples/drivers/led/pwm/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 13 additions & 1 deletion samples/drivers/led/pwm/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a75ed26

Please sign in to comment.