Pico Blink
Returning to my Pico journey, let’s make it blink.
Haven’t touched the Pico in about 5 months, so time to get back to it.
Let’s start simple:
#include <stdio.h>
#include "pico/stdlib.h"
int main()
{
stdio_init_all();
printf("Hello, world!\n");
return 0;
}
So far so good. Had minicom at 9600 baud for some reason, but it should be 115200. Other than that, it worked.
Blink
Let’s make it blink. The SDK now supports high-level functions, so let’s use them.
#include "pico/status_led.h"
#include "pico/stdlib.h"
#include <stdio.h>
int main()
{
stdio_init_all();
if (status_led_init()) {
while (true) {
status_led_set_state(true);
sleep_ms(500);
status_led_set_state(false);
sleep_ms(500);
}
}
else {
printf("Cannot initialise status LED\n");
}
return 0;
}
Don’t forget to add pico_status_led as a library to the probject:
# Add any user requested libraries
target_link_libraries(blink
pico_status_led
)
And it’s blinking.