1 /* 2 * Copyright (c) 2018 Linaro Limited 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/device.h> 8 #include <errno.h> 9 #include <zephyr/drivers/led.h> 10 #include <zephyr/sys/util.h> 11 #include <zephyr/kernel.h> 12 13 #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL 14 #include <zephyr/logging/log.h> 15 LOG_MODULE_REGISTER(app); 16 17 #define NUM_LEDS 16 18 19 #define DELAY_TIME K_MSEC(1000) 20 main(void)21int main(void) 22 { 23 const struct device *const led_dev = DEVICE_DT_GET_ANY(ti_lp3943); 24 int i, ret; 25 26 if (!led_dev) { 27 LOG_ERR("No device with compatible ti,lp3943 found"); 28 return 0; 29 } else if (!device_is_ready(led_dev)) { 30 LOG_ERR("LED device %s not ready", led_dev->name); 31 return 0; 32 } else { 33 LOG_INF("Found LED device %s", led_dev->name); 34 } 35 36 /* 37 * Display a continuous pattern that turns on 16 LEDs at 1s one by 38 * one until it reaches the end and turns off LEDs in reverse order. 39 */ 40 41 LOG_INF("Displaying the pattern"); 42 43 while (1) { 44 /* Turn on LEDs one by one */ 45 for (i = 0; i < NUM_LEDS; i++) { 46 ret = led_on(led_dev, i); 47 if (ret < 0) { 48 return 0; 49 } 50 51 k_sleep(DELAY_TIME); 52 } 53 54 /* Turn off LEDs one by one */ 55 for (i = NUM_LEDS - 1; i >= 0; i--) { 56 ret = led_off(led_dev, i); 57 if (ret < 0) { 58 return 0; 59 } 60 61 k_sleep(DELAY_TIME); 62 } 63 } 64 return 0; 65 } 66