|
8 | 8 | #include "pico/stdlib.h"
|
9 | 9 | #include "hardware/gpio.h"
|
10 | 10 |
|
11 |
| -const uint LED_PIN = PICO_DEFAULT_LED_PIN; |
12 | 11 | const uint DOT_PERIOD_MS = 100;
|
13 | 12 |
|
14 | 13 | const char *morse_letters[] = {
|
@@ -40,36 +39,41 @@ const char *morse_letters[] = {
|
40 | 39 | "--.." // Z
|
41 | 40 | };
|
42 | 41 |
|
43 |
| -void put_morse_letter(const char *pattern) { |
| 42 | +void put_morse_letter(uint led_pin, const char *pattern) { |
44 | 43 | for (; *pattern; ++pattern) {
|
45 |
| - gpio_put(LED_PIN, 1); |
| 44 | + gpio_put(led_pin, 1); |
46 | 45 | if (*pattern == '.')
|
47 | 46 | sleep_ms(DOT_PERIOD_MS);
|
48 | 47 | else
|
49 | 48 | sleep_ms(DOT_PERIOD_MS * 3);
|
50 |
| - gpio_put(LED_PIN, 0); |
| 49 | + gpio_put(led_pin, 0); |
51 | 50 | sleep_ms(DOT_PERIOD_MS * 1);
|
52 | 51 | }
|
53 | 52 | sleep_ms(DOT_PERIOD_MS * 2);
|
54 | 53 | }
|
55 | 54 |
|
56 |
| -void put_morse_str(const char *str) { |
| 55 | +void put_morse_str(uint led_pin, const char *str) { |
57 | 56 | for (; *str; ++str) {
|
58 | 57 | if (*str >= 'A' && *str < 'Z') {
|
59 |
| - put_morse_letter(morse_letters[*str - 'A']); |
| 58 | + put_morse_letter(led_pin, morse_letters[*str - 'A']); |
60 | 59 | } else if (*str >= 'a' && *str < 'z') {
|
61 |
| - put_morse_letter(morse_letters[*str - 'a']); |
| 60 | + put_morse_letter(led_pin, morse_letters[*str - 'a']); |
62 | 61 | } else if (*str == ' ') {
|
63 | 62 | sleep_ms(DOT_PERIOD_MS * 4);
|
64 | 63 | }
|
65 | 64 | }
|
66 | 65 | }
|
67 | 66 |
|
68 | 67 | int main() {
|
| 68 | +#ifndef PICO_DEFAULT_LED_PIN |
| 69 | +#warning picoboard/blinky example requires a board with a regular LED |
| 70 | +#else |
| 71 | + const uint LED_PIN = PICO_DEFAULT_LED_PIN; |
69 | 72 | gpio_init(LED_PIN);
|
70 | 73 | gpio_set_dir(LED_PIN, GPIO_OUT);
|
71 | 74 | while (true) {
|
72 |
| - put_morse_str("Hello world"); |
| 75 | + put_morse_str(LED_PIN, "Hello world"); |
73 | 76 | sleep_ms(1000);
|
74 | 77 | }
|
| 78 | +#endif |
75 | 79 | }
|
0 commit comments