1 /*
2  * Copyright (c) 2019 Henrik Brix Andersen <henrik@brixandersen.dk>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/led.h>
8 #include <zephyr/devicetree.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/logging/log.h>
11 
12 LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
13 
14 #define LED_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(holtek_ht16k33)
15 
main(void)16 int main(void)
17 {
18 	const struct device *const led = DEVICE_DT_GET(LED_NODE);
19 	int i;
20 
21 	if (!device_is_ready(led)) {
22 		LOG_ERR("LED device not ready");
23 		return 0;
24 	}
25 
26 	while (1) {
27 		LOG_INF("Iterating through all LEDs, turning them on "
28 			"one-by-one");
29 		for (i = 0; i < 128; i++) {
30 			led_on(led, i);
31 			k_sleep(K_MSEC(100));
32 		}
33 
34 		for (i = 500; i <= 2000; i *= 2) {
35 			LOG_INF("Blinking LEDs with a period of %d ms", i);
36 			led_blink(led, 0, i / 2, i / 2);
37 			k_msleep(10 * i);
38 		}
39 		led_blink(led, 0, 0, 0);
40 
41 		for (i = 100; i >= 0; i -= 10) {
42 			LOG_INF("Setting LED brightness to %d%%", i);
43 			led_set_brightness(led, 0, i);
44 			k_sleep(K_MSEC(1000));
45 		}
46 
47 		LOG_INF("Turning all LEDs off and restoring 100%% brightness");
48 		for (i = 0; i < 128; i++) {
49 			led_off(led, i);
50 		}
51 		led_set_brightness(led, 0, 100);
52 	}
53 	return 0;
54 }
55