Skip to content

Commit 6f2fb1b

Browse files
committed
Implement blinky with led strip
1 parent f0d3679 commit 6f2fb1b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

app/src/main.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
#include <zephyr/drivers/gpio.h>
2+
#include <zephyr/drivers/led_strip.h>
23
#include <zephyr/kernel.h>
34
#include <zephyr/logging/log.h>
45

56
#define SLEEP_TIME_MS 1000
67

78
/* 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
911

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);
1113

1214
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
1315

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+
1420
int main(void)
1521
{
22+
if (!device_is_ready(strip)) return 0;
1623
bool led_state = true;
1724

18-
if (!gpio_is_ready_dt(&led)) return 0;
19-
20-
if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) return 0;
21-
2225
while (1) {
23-
if (gpio_pin_toggle_dt(&led) < 0) return 0;
24-
2526
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+
}
2632
LOG_INF("LED state: %s", led_state ? "ON" : "OFF");
2733
k_msleep(SLEEP_TIME_MS);
2834
}
2935
return 0;
3036
}
37+

0 commit comments

Comments
 (0)