|
1 | 1 | #include <zephyr/drivers/gpio.h> |
| 2 | +#include <zephyr/drivers/led_strip.h> |
2 | 3 | #include <zephyr/kernel.h> |
3 | 4 | #include <zephyr/logging/log.h> |
4 | 5 |
|
5 | 6 | #define SLEEP_TIME_MS 1000 |
6 | 7 |
|
7 | 8 | /* The devicetree node identifier for the "led0" alias. */ |
8 | | -#define LED_NODE DT_ALIAS(led0) |
| 9 | +#define STRIP_NODE DT_ALIAS(led_strip) |
| 10 | +#define LED_COUNT 1 |
9 | 11 |
|
10 | | -static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios); |
| 12 | +static const struct device *const strip = DEVICE_DT_GET(STRIP_NODE); |
11 | 13 |
|
12 | 14 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); |
13 | 15 |
|
| 16 | +/* LED Color Definitions. */ |
| 17 | +static struct led_rgb red = { .r = 255, .g = 0, .b = 0 }; |
| 18 | +static struct led_rgb off = { .r = 0, .g = 0, .b = 0 }; |
| 19 | + |
14 | 20 | int main(void) |
15 | 21 | { |
| 22 | + if (!device_is_ready(strip)) return 0; |
16 | 23 | bool led_state = true; |
17 | 24 |
|
18 | | - if (!gpio_is_ready_dt(&led)) return 0; |
19 | | - |
20 | | - if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) return 0; |
21 | | - |
22 | 25 | while (1) { |
23 | | - if (gpio_pin_toggle_dt(&led) < 0) return 0; |
24 | | - |
25 | 26 | led_state = !led_state; |
| 27 | + if (led_state) { |
| 28 | + led_strip_update_rgb(strip, &red, LED_COUNT); |
| 29 | + } else { |
| 30 | + led_strip_update_rgb(strip, &off, LED_COUNT); |
| 31 | + } |
26 | 32 | LOG_INF("LED state: %s", led_state ? "ON" : "OFF"); |
27 | 33 | k_msleep(SLEEP_TIME_MS); |
28 | 34 | } |
29 | 35 | return 0; |
30 | 36 | } |
| 37 | + |
0 commit comments