Skip to content

Instantly share code, notes, and snippets.

@cadr
Created April 25, 2021 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cadr/6aa94398ce0817784c82cf26420faa59 to your computer and use it in GitHub Desktop.
Save cadr/6aa94398ce0817784c82cf26420faa59 to your computer and use it in GitHub Desktop.
ESP32/Arduino code to have morse paddle as BLE keyboard
//Inspriation from http://oz1jhm.dk/content/hamradio-solutions-vband-interface
//But modified to work with esp32 BLE as a keyboard.
//Am using as input to the iOS "Morse-It" app
//Note that this BleKeyboard library needs to be download and added - see https://github.com/T-vK/ESP32-BLE-Keyboard
#include <BleKeyboard.h>
#include <Bounce2.h>
# define DIH_PIN 26
# define DAH_PIN 25
# define BOUNCE_INTERVAL 5
BleKeyboard bleKeyboard("BLE_MorseKey");
Bounce bDih = Bounce();
Bounce bDah = Bounce();
void setup() {
bDih.attach(DIH_PIN, INPUT_PULLUP);
bDih.interval(BOUNCE_INTERVAL);
bDah.attach(DAH_PIN, INPUT_PULLUP);
bDah.interval(BOUNCE_INTERVAL);
bleKeyboard.begin();
}
void loop() {
if(bleKeyboard.isConnected()) {
bDih.update();
bDah.update();
if ( bDih.fell() ) {
bleKeyboard.press(KEY_F1);
}
if ( bDih.rose() ) {
bleKeyboard.release(KEY_F1);
}
if ( bDah.fell() ) {
bleKeyboard.press(KEY_F2);
}
if ( bDah.rose() ) {
bleKeyboard.release(KEY_F2);
}
} else {
delay(20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment