From 706e514ba46a54778473bfa7ed28327e833c599f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Sat, 10 Feb 2024 23:51:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/keyer.cpp | 24 ++++++++++++++++++++++-- src/keyer.h | 6 ++++-- src/pico_keyer.cpp | 5 +++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/keyer.cpp b/src/keyer.cpp index 83f631d..b4389dc 100644 --- a/src/keyer.cpp +++ b/src/keyer.cpp @@ -1,11 +1,31 @@ +#include + +#include "pico/stdlib.h" + #include "keyer.h" +extern const uint LEFT_PADDLE_PIN; + +bool left_paddle_pressed() +{ + if (gpio_get(LEFT_PADDLE_PIN)) + { + return true; + } + return false; +} + void Keyer::run() { switch (state) { - case State::WAIT: - // do nothing + case State::Wait: + if (left_paddle_pressed()) + state = State::LeftPaddlePressed; + break; + case State::LeftPaddlePressed: + printf("."); + state = State::Wait; break; default: diff --git a/src/keyer.h b/src/keyer.h index 96abae0..98b7c7f 100644 --- a/src/keyer.h +++ b/src/keyer.h @@ -6,13 +6,15 @@ class Keyer final public: enum class State { - WAIT + Wait, + LeftPaddlePressed, + }; void run(); private: - State state{State::WAIT}; + State state{State::Wait}; }; #endif \ No newline at end of file diff --git a/src/pico_keyer.cpp b/src/pico_keyer.cpp index 095acac..d29cf40 100644 --- a/src/pico_keyer.cpp +++ b/src/pico_keyer.cpp @@ -8,9 +8,10 @@ namespace { const uint LED_PIN = PICO_DEFAULT_LED_PIN; - const uint LEFT_PADDLE_PIN = 14; + const uint RIGHT_PADDLE_PIN = 15; } +extern const uint LEFT_PADDLE_PIN = 14; void setup() { @@ -45,7 +46,7 @@ int main() while (true) { - sleep_ms(10); + sleep_ms(1.2 * settings.wpm); keyer.run(); }