Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 colored_status_led API if supported by the board.

### System

App|Description
Expand Down
2 changes: 2 additions & 0 deletions status_led/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(status_blink)
add_subdirectory(color_blink)
14 changes: 14 additions & 0 deletions status_led/color_blink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
35 changes: 35 additions & 0 deletions status_led/color_blink/color_blink.c
Original file line number Diff line number Diff line change
@@ -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();
}
16 changes: 16 additions & 0 deletions status_led/status_blink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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
)
# 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)
26 changes: 26 additions & 0 deletions status_led/status_blink/status_blink.c
Original file line number Diff line number Diff line change
@@ -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();
}