Skip to content

Commit 5dc6b08

Browse files
committed
Update blink example to use status_led lib
1 parent f83b933 commit 5dc6b08

File tree

2 files changed

+10
-40
lines changed

2 files changed

+10
-40
lines changed

blink/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ add_executable(blink
33
)
44

55
# pull in common dependencies
6-
target_link_libraries(blink pico_stdlib)
7-
8-
if (PICO_CYW43_SUPPORTED)
9-
target_link_libraries(blink pico_cyw43_arch_none)
10-
endif()
6+
target_link_libraries(blink pico_stdlib pico_status_led)
117

128
# create map/bin/hex file etc.
139
pico_add_extra_outputs(blink)

blink/blink.c

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,23 @@
55
*/
66

77
#include "pico/stdlib.h"
8-
9-
// Pico W devices use a GPIO on the WIFI chip for the LED,
10-
// so when building for Pico W, CYW43_WL_GPIO_LED_PIN will be defined
11-
#ifdef CYW43_WL_GPIO_LED_PIN
12-
#include "pico/cyw43_arch.h"
13-
#endif
8+
#include "pico/status_led.h"
149

1510
#ifndef LED_DELAY_MS
1611
#define LED_DELAY_MS 250
1712
#endif
1813

19-
// Perform initialisation
20-
int pico_led_init(void) {
21-
#if defined(PICO_DEFAULT_LED_PIN)
22-
// A device like Pico that uses a GPIO for the LED will define PICO_DEFAULT_LED_PIN
23-
// so we can use normal GPIO functionality to turn the led on and off
24-
gpio_init(PICO_DEFAULT_LED_PIN);
25-
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
26-
return PICO_OK;
27-
#elif defined(CYW43_WL_GPIO_LED_PIN)
28-
// For Pico W devices we need to initialise the driver etc
29-
return cyw43_arch_init();
30-
#endif
31-
}
32-
33-
// Turn the led on or off
34-
void pico_set_led(bool led_on) {
35-
#if defined(PICO_DEFAULT_LED_PIN)
36-
// Just set the GPIO on or off
37-
gpio_put(PICO_DEFAULT_LED_PIN, led_on);
38-
#elif defined(CYW43_WL_GPIO_LED_PIN)
39-
// Ask the wifi "driver" to set the GPIO on or off
40-
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_on);
41-
#endif
42-
}
43-
4414
int main() {
45-
int rc = pico_led_init();
46-
hard_assert(rc == PICO_OK);
15+
bool rc = pico_status_led_init(NULL);
16+
hard_assert(rc);
4717
while (true) {
48-
pico_set_led(true);
18+
pico_status_led_set(true);
19+
pico_status_led_color_set(true);
4920
sleep_ms(LED_DELAY_MS);
50-
pico_set_led(false);
21+
assert(pico_status_led_get());
22+
pico_status_led_set(false);
23+
pico_status_led_color_set(false);
5124
sleep_ms(LED_DELAY_MS);
25+
assert(!pico_status_led_get());
5226
}
5327
}

0 commit comments

Comments
 (0)