-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMorseMouse.ino
36 lines (28 loc) · 1.09 KB
/
MorseMouse.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//for use with an Arduino Leonardo (or similar clone),
//that has the ability to emulate a mouse and send mouse clicks to a connected PC
#include <Mouse.h>
#define MorseKeyPin 11 //set this as you hooked it up to your Leonardo
bool mousebuttonstate = 0;
//using this variable as a state prevents us from sending excessive events to the PC
void setup() {
pinMode(MorseKeyPin, INPUT_PULLUP);
Mouse.begin(); //initiate the Mouse library
Serial.begin(9600);
}
void loop() {
if ( (digitalRead(MorseKeyPin) == LOW) && (mousebuttonstate == 0) ) {
Serial.println("pressed");
Mouse.press();
mousebuttonstate = 1;
digitalWrite(LED_BUILTIN, HIGH);
}
if ( (digitalRead(MorseKeyPin) == HIGH) && (mousebuttonstate == 1) ) {
Serial.println("released");
Mouse.release();
mousebuttonstate = 0;
digitalWrite(LED_BUILTIN, LOW);
}
delay(10); //used to debounce physical morse keys.
//Never set to 0, unless you use an electronic keyer.
//adjust to your keying speed. lower delays = faster keying
}