-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (28 loc) · 828 Bytes
/
main.cpp
File metadata and controls
34 lines (28 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
#define LED_NODE DT_ALIAS(app_led)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);
int main(void)
{
bool led_state = true;
if (!gpio_is_ready_dt(&led)) {
LOG_ERR("LED not ready!");
return -1;
}
if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) {
LOG_ERR("Unable to configure LED!");
return -1;
}
while (1) {
led_state = !led_state;
if (gpio_pin_toggle_dt(&led) < 0) {
LOG_ERR("Unable to toggle the LED!");
return -1;
}
LOG_INF("LED state: %s", led_state ? "ON" : "OFF");
k_msleep(CONFIG_APP_HEARTBEAT_PERIOD_MS);
}
return 0;
}