Fix examples to build cleanly if PICO_DEFAULT_LED_PIN isn't defined
This commit is contained in:
parent
482d9657d3
commit
4d7882bc59
@ -7,6 +7,9 @@
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
int main() {
|
||||
#ifndef PICO_DEFAULT_LED_PIN
|
||||
#warning blink example requires a board with a regular LED
|
||||
#else
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
@ -16,4 +19,5 @@ int main() {
|
||||
gpio_put(LED_PIN, 0);
|
||||
sleep_ms(250);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/gpio.h"
|
||||
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
const uint DOT_PERIOD_MS = 100;
|
||||
|
||||
const char *morse_letters[] = {
|
||||
@ -40,25 +39,25 @@ const char *morse_letters[] = {
|
||||
"--.." // Z
|
||||
};
|
||||
|
||||
void put_morse_letter(const char *pattern) {
|
||||
void put_morse_letter(uint led_pin, const char *pattern) {
|
||||
for (; *pattern; ++pattern) {
|
||||
gpio_put(LED_PIN, 1);
|
||||
gpio_put(led_pin, 1);
|
||||
if (*pattern == '.')
|
||||
sleep_ms(DOT_PERIOD_MS);
|
||||
else
|
||||
sleep_ms(DOT_PERIOD_MS * 3);
|
||||
gpio_put(LED_PIN, 0);
|
||||
gpio_put(led_pin, 0);
|
||||
sleep_ms(DOT_PERIOD_MS * 1);
|
||||
}
|
||||
sleep_ms(DOT_PERIOD_MS * 2);
|
||||
}
|
||||
|
||||
void put_morse_str(const char *str) {
|
||||
void put_morse_str(uint led_pin, const char *str) {
|
||||
for (; *str; ++str) {
|
||||
if (*str >= 'A' && *str < 'Z') {
|
||||
put_morse_letter(morse_letters[*str - 'A']);
|
||||
put_morse_letter(led_pin, morse_letters[*str - 'A']);
|
||||
} else if (*str >= 'a' && *str < 'z') {
|
||||
put_morse_letter(morse_letters[*str - 'a']);
|
||||
put_morse_letter(led_pin, morse_letters[*str - 'a']);
|
||||
} else if (*str == ' ') {
|
||||
sleep_ms(DOT_PERIOD_MS * 4);
|
||||
}
|
||||
@ -66,10 +65,15 @@ void put_morse_str(const char *str) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
#ifndef PICO_DEFAULT_LED_PIN
|
||||
#warning picoboard/blinky example requires a board with a regular LED
|
||||
#else
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
while (true) {
|
||||
put_morse_str("Hello world");
|
||||
put_morse_str(LED_PIN, "Hello world");
|
||||
sleep_ms(1000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() {
|
||||
|
||||
int main() {
|
||||
#ifndef PICO_DEFAULT_LED_PIN
|
||||
#warning picobooard/button example requires a board with a regular LED
|
||||
#warning picoboard/button example requires a board with a regular LED
|
||||
#else
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
|
||||
@ -26,6 +26,10 @@ void pio_pwm_set_level(PIO pio, uint sm, uint32_t level) {
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
#ifndef PICO_DEFAULT_LED_PIN
|
||||
#warning pio/pwm example requires a board with a regular LED
|
||||
puts("Default LED pin was not defined");
|
||||
#else
|
||||
|
||||
// todo get free sm
|
||||
PIO pio = pio0;
|
||||
@ -43,4 +47,5 @@ int main() {
|
||||
level = (level + 1) % 256;
|
||||
sleep_ms(10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -13,6 +13,9 @@
|
||||
// `pico_bootsel_via_double_reset` library!
|
||||
|
||||
int main() {
|
||||
#ifndef PICO_DEFAULT_LED_PIN
|
||||
#warning system/hello_double_tap example requires a board with a regular LED
|
||||
#else
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
@ -22,4 +25,5 @@ int main() {
|
||||
gpio_put(LED_PIN, 0);
|
||||
sleep_ms(250);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user