more experiments

This commit is contained in:
Martin Brodbeck 2024-02-11 15:45:12 +01:00
parent 706e514ba4
commit 5bfe72553f
3 changed files with 29 additions and 6 deletions

View file

@ -8,7 +8,7 @@ extern const uint LEFT_PADDLE_PIN;
bool left_paddle_pressed() bool left_paddle_pressed()
{ {
if (gpio_get(LEFT_PADDLE_PIN)) if (!gpio_get(LEFT_PADDLE_PIN))
{ {
return true; return true;
} }
@ -25,7 +25,20 @@ void Keyer::run()
break; break;
case State::LeftPaddlePressed: case State::LeftPaddlePressed:
printf("."); printf(".");
state = State::Wait;
if (left_paddle_pressed())
state = State::InterCharSpace;
else
state = State::Wait;
break;
case State::InterCharSpace:
printf("(.)");
if (left_paddle_pressed())
state = State::LeftPaddlePressed;
else
state = State::Wait;
break; break;
default: default:

View file

@ -8,6 +8,7 @@ public:
{ {
Wait, Wait,
LeftPaddlePressed, LeftPaddlePressed,
InterCharSpace,
}; };
@ -15,6 +16,13 @@ public:
private: private:
State state{State::Wait}; State state{State::Wait};
uint8_t numElements{0};
}; };
inline uint64_t element_duration_us(uint8_t wpm)
{
uint64_t duration = static_cast<uint64_t>(1.2 / static_cast<uint64_t>(wpm) * 1000 * 1000);
return duration;
}
#endif #endif

View file

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h>
#include "pico/stdlib.h" #include "pico/stdlib.h"
@ -23,10 +24,10 @@ void setup()
// Setup pins for left and right paddles // Setup pins for left and right paddles
gpio_init(LEFT_PADDLE_PIN); gpio_init(LEFT_PADDLE_PIN);
gpio_set_dir(LEFT_PADDLE_PIN, GPIO_IN); gpio_set_dir(LEFT_PADDLE_PIN, GPIO_IN);
gpio_pull_down(LEFT_PADDLE_PIN); gpio_pull_up(LEFT_PADDLE_PIN);
gpio_init(RIGHT_PADDLE_PIN); gpio_init(RIGHT_PADDLE_PIN);
gpio_set_dir(RIGHT_PADDLE_PIN, GPIO_IN); gpio_set_dir(RIGHT_PADDLE_PIN, GPIO_IN);
gpio_pull_down(RIGHT_PADDLE_PIN); gpio_pull_up(RIGHT_PADDLE_PIN);
} }
int main() int main()
@ -39,14 +40,15 @@ int main()
Settings settings{read_settings()}; Settings settings{read_settings()};
printf("Iambic mode (loaded): %d\n", static_cast<int>(settings.mode)); printf("\nIambic mode (loaded): %d\n", static_cast<int>(settings.mode));
printf("WPM (loaded): %d\n", settings.wpm); printf("WPM (loaded): %d\n", settings.wpm);
printf("Element duration (u_sec): %" PRIu64 "\n", element_duration_us(settings.wpm));
Keyer keyer; Keyer keyer;
while (true) while (true)
{ {
sleep_ms(1.2 * settings.wpm); sleep_us(element_duration_us(settings.wpm));
keyer.run(); keyer.run();
} }