Browse Source

samples: blinky: add verbose printf output

Add console output to the sample, with the LED status upon a GPIO toggle.

Signed-off-by: Patryk Koscik <pkoscik@antmicro.com>
pull/66540/head
Patryk Koscik 2 years ago committed by Fabio Baltieri
parent
commit
b22bb172f2
  1. 5
      samples/basic/blinky/README.rst
  2. 5
      samples/basic/blinky/src/main.c

5
samples/basic/blinky/README.rst

@ -40,8 +40,9 @@ Build and flash Blinky as follows, changing ``reel_board`` for your board: @@ -40,8 +40,9 @@ Build and flash Blinky as follows, changing ``reel_board`` for your board:
:goals: build flash
:compact:
After flashing, the LED starts to blink. If a runtime error occurs, the sample
exits without printing to the console.
After flashing, the LED starts to blink and messages with the current LED state
are printed on the console. If a runtime error occurs, the sample exits without
printing to the console.
Build errors
************

5
samples/basic/blinky/src/main.c

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
@ -22,6 +23,7 @@ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); @@ -22,6 +23,7 @@ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
int main(void)
{
int ret;
bool led_state = true;
if (!gpio_is_ready_dt(&led)) {
return 0;
@ -37,6 +39,9 @@ int main(void) @@ -37,6 +39,9 @@ int main(void)
if (ret < 0) {
return 0;
}
led_state = !led_state;
printf("LED state: %s\n", led_state ? "ON" : "OFF");
k_msleep(SLEEP_TIME_MS);
}
return 0;

Loading…
Cancel
Save