This commit is contained in:
Martin Brodbeck 2024-02-10 23:51:55 +01:00
parent 49e3a19f1f
commit 706e514ba4
3 changed files with 29 additions and 6 deletions

View file

@ -1,11 +1,31 @@
#include <stdio.h>
#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:

View file

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

View file

@ -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();
}