add rgb blink

This commit is contained in:
MReenen 2024-02-24 22:57:18 +01:00
parent 6d19e1dc97
commit 89f2db72d0
2 changed files with 33 additions and 6 deletions

View File

@ -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)

View File

@ -1,9 +1,36 @@
#include <stdio.h>
#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;
}