From 89f2db72d0366f619f64f868b371dd44345c34c5 Mon Sep 17 00:00:00 2001 From: MReenen Date: Sat, 24 Feb 2024 22:57:18 +0100 Subject: [PATCH] add rgb blink --- CMakeLists.txt | 6 +++--- src/main.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24f2736..39b3bbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,12 @@ project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() -add_executable(hello_world +add_executable(my_project src/main.c ) # Add pico_stdlib library which aggregates commonly used features -target_link_libraries(hello_world pico_stdlib) +target_link_libraries(my_project pico_stdlib) # create map/bin/hex/uf2 file in addition to ELF. -pico_add_extra_outputs(hello_world) +pico_add_extra_outputs(my_project) diff --git a/src/main.c b/src/main.c index d2848ca..411626b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,9 +1,36 @@ #include #include "pico/stdlib.h" +// pin rgb led on Seeed XIAO RP2040 +#define PIN_RGB_R 17 +#define PIN_RGB_G 16 +#define PIN_RGB_B 25 + int main() { - setup_default_uart(); - printf("Hello, world!\n"); - return 0; + setup_default_uart(); + printf("Hello, world!\n"); + + gpio_init(PIN_RGB_R); + gpio_set_dir(PIN_RGB_R, GPIO_OUT); + gpio_init(PIN_RGB_G); + gpio_set_dir(PIN_RGB_G, GPIO_OUT); + gpio_init(PIN_RGB_B); + gpio_set_dir(PIN_RGB_B, GPIO_OUT); + while (true) + { + gpio_put(PIN_RGB_G, 1); + sleep_ms(250); + gpio_put(PIN_RGB_R, 0); + sleep_ms(250); + gpio_put(PIN_RGB_B, 1); + sleep_ms(250); + gpio_put(PIN_RGB_G, 0); + sleep_ms(250); + gpio_put(PIN_RGB_R, 1); + sleep_ms(250); + gpio_put(PIN_RGB_B, 0); + sleep_ms(250); + } + return 0; }