From e21bce77c92c8901201e74485cda0c9457829ffb Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 28 Jul 2025 19:40:31 +0100 Subject: [PATCH 1/3] Demonstrate using the status led API --- CMakeLists.txt | 1 + README.md | 7 ++++++ status_led/CMakeLists.txt | 2 ++ status_led/color_blink/CMakeLists.txt | 14 +++++++++++ status_led/color_blink/color_blink.c | 35 ++++++++++++++++++++++++++ status_led/status_blink/CMakeLists.txt | 14 +++++++++++ status_led/status_blink/status_blink.c | 26 +++++++++++++++++++ 7 files changed, 99 insertions(+) create mode 100644 status_led/CMakeLists.txt create mode 100644 status_led/color_blink/CMakeLists.txt create mode 100644 status_led/color_blink/color_blink.c create mode 100644 status_led/status_blink/CMakeLists.txt create mode 100644 status_led/status_blink/status_blink.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 33992dec8..ab8f3f34b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ add_subdirectory(pwm) add_subdirectory(reset) add_subdirectory(rtc) add_subdirectory(spi) +add_subdirectory(status_led) add_subdirectory(system) add_subdirectory(timer) add_subdirectory(uart) diff --git a/README.md b/README.md index 9d1a8b195..9f5f0d14a 100644 --- a/README.md +++ b/README.md @@ -371,6 +371,13 @@ App|Description [max7219_8x7seg_spi](spi/max7219_8x7seg_spi) | Attaching a Max7219 driving an 8 digit 7 segment display via SPI. [max7219_32x8_spi](spi/max7219_32x8_spi) | Attaching a Max7219 driving an 32x8 LED display via SPI. +### Status Led + +App|Description +---|--- +[status_blink](status_led/status_blink) | Blink the onboard LED using the status LED API. +[color_blink](status_led/color_blink) | Blink the onboard colored (WS2812) LED using the status LED API if supported by the board. + ### System App|Description diff --git a/status_led/CMakeLists.txt b/status_led/CMakeLists.txt new file mode 100644 index 000000000..e1cfd1e68 --- /dev/null +++ b/status_led/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(status_blink) +add_subdirectory(color_blink) diff --git a/status_led/color_blink/CMakeLists.txt b/status_led/color_blink/CMakeLists.txt new file mode 100644 index 000000000..80fa4639b --- /dev/null +++ b/status_led/color_blink/CMakeLists.txt @@ -0,0 +1,14 @@ +# Blink the colored "status" LED connected to the GPIO defined by PICO_DEFAULT_WS2812_PIN for your board +add_executable(color_blink + color_blink.c +) +# You can define PICO_DEFAULT_WS2812_PIN yourself to add a WS2812 led to a normal GPIO +#target_compile_definitions(color_blink PRIVATE +# PICO_DEFAULT_WS2812_PIN=16 +#) +target_link_libraries(color_blink + pico_stdlib + pico_status_led +) +pico_add_extra_outputs(color_blink) +example_auto_set_url(color_blink) diff --git a/status_led/color_blink/color_blink.c b/status_led/color_blink/color_blink.c new file mode 100644 index 000000000..dbdfe896d --- /dev/null +++ b/status_led/color_blink/color_blink.c @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/stdlib.h" +#include "pico/status_led.h" + +#if !PICO_COLORED_STATUS_LED_AVAILABLE +#warning The color_blink example requires a board with a WS2812 LED +#endif + +#ifndef LED_DELAY_MS +#define LED_DELAY_MS 250 +#endif + +int main() { + bool rc = status_led_init(); + hard_assert(rc); + hard_assert(colored_status_led_supported()); // This assert fails if your board does not have WS2812 support + uint32_t count = 0; + while (true) { + // flash red then green then blue + uint32_t color = PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(count % 3 == 0 ? 0xaa : 0, count % 3 == 1 ? 0xaa : 0, count % 3 == 2 ? 0xaa : 0); + colored_status_led_set_on_with_color(color); + count++; + sleep_ms(LED_DELAY_MS); + assert(colored_status_led_get_state()); + colored_status_led_set_state(false); + sleep_ms(LED_DELAY_MS); + assert(!colored_status_led_get_state()); + } + status_led_deinit(); +} diff --git a/status_led/status_blink/CMakeLists.txt b/status_led/status_blink/CMakeLists.txt new file mode 100644 index 000000000..4f8b5ab44 --- /dev/null +++ b/status_led/status_blink/CMakeLists.txt @@ -0,0 +1,14 @@ +# Blink the "status" LED connected to the GPIO defined by PICO_DEFAULT_LED_PIN for your board +add_executable(status_blink + status_blink.c +) +# You can define PICO_DEFAULT_LED_PIN yourself to add a led to a different GPIO +#target_compile_definitions(status_blink PRIVATE +# PICO_DEFAULT_LED_PIN=15 +#) +target_link_libraries(status_blink + pico_stdlib + pico_status_led +) +pico_add_extra_outputs(status_blink) +example_auto_set_url(status_blink) diff --git a/status_led/status_blink/status_blink.c b/status_led/status_blink/status_blink.c new file mode 100644 index 000000000..e798f865d --- /dev/null +++ b/status_led/status_blink/status_blink.c @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/stdlib.h" +#include "pico/status_led.h" + +#ifndef LED_DELAY_MS +#define LED_DELAY_MS 250 +#endif + +int main() { + bool rc = status_led_init(); + hard_assert(rc); + while (true) { + status_led_set_state(true); + sleep_ms(LED_DELAY_MS); + assert(status_led_get_state()); + status_led_set_state(false); + sleep_ms(LED_DELAY_MS); + assert(!status_led_get_state()); + } + status_led_deinit(); +} From bdb32323c0650e5c6b19a6a65e5397a763ea71ce Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 28 Jul 2025 15:32:03 -0500 Subject: [PATCH 2/3] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f5f0d14a..810895fca 100644 --- a/README.md +++ b/README.md @@ -371,12 +371,12 @@ App|Description [max7219_8x7seg_spi](spi/max7219_8x7seg_spi) | Attaching a Max7219 driving an 8 digit 7 segment display via SPI. [max7219_32x8_spi](spi/max7219_32x8_spi) | Attaching a Max7219 driving an 32x8 LED display via SPI. -### Status Led +### Status LED App|Description ---|--- -[status_blink](status_led/status_blink) | Blink the onboard LED using the status LED API. -[color_blink](status_led/color_blink) | Blink the onboard colored (WS2812) LED using the status LED API if supported by the board. +[status_blink](status_led/status_blink) | Blink the onboard LED using the status_led API. +[color_blink](status_led/color_blink) | Blink the onboard colored (WS2812) LED using the colored_status_led API if supported by the board. ### System From 1f53cc6b1849aa529ff34373638fb233d23b966b Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 28 Jul 2025 15:37:48 -0500 Subject: [PATCH 3/3] Update CMakeLists.txt --- status_led/status_blink/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/status_led/status_blink/CMakeLists.txt b/status_led/status_blink/CMakeLists.txt index 4f8b5ab44..531edad90 100644 --- a/status_led/status_blink/CMakeLists.txt +++ b/status_led/status_blink/CMakeLists.txt @@ -1,4 +1,6 @@ -# Blink the "status" LED connected to the GPIO defined by PICO_DEFAULT_LED_PIN for your board +# Blink the "status" LED either connected to the GPIO defined by PICO_DEFAULT_LED_PIN for your board +# or via the WiFi chip on boards like Pico 2 or Pico 2 W + add_executable(status_blink status_blink.c )