Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OllieBck
committed
Aug 27, 2018
0 parents
commit 29f618d
Showing
4 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include<Keyboard.h> | ||
#include "morseKeyboard.h" | ||
|
||
int buzzerPin = A0; | ||
int debounceTime = 400; // prepare for noisy buttons | ||
int ditPin = A2; | ||
int dahPin = A3; | ||
int ditSound = 880; | ||
int dahSound = 500; | ||
int ditSoundDuration = 500; | ||
int dahSoundDuration = 550; | ||
int speedTyper = 400; // time for key repeats | ||
int speedSense = 3; | ||
bool activeButtonValue = LOW; | ||
|
||
char ditKey = 46; | ||
char dahKey = 45; | ||
char altDitKey = 204; | ||
char altDahKey = 205; | ||
|
||
KeyboardKey shortKey(ditPin, ditKey, altDitKey, debounceTime, buzzerPin, ditSound, ditSoundDuration, activeButtonValue); | ||
KeyboardKey longKey(dahPin, dahKey, altDahKey, debounceTime, buzzerPin, dahSound, dahSoundDuration, activeButtonValue); | ||
//AccessKey accessButton(accessPin, debounceTime, activeButtonValue); | ||
|
||
void setup() { | ||
// put your setup code here, to run once: | ||
Serial.begin(9600); | ||
Keyboard.begin(); | ||
} | ||
|
||
void loop() { | ||
|
||
//bool shiftValue = bleAccessButton.Check(); | ||
bool shiftValue = false; | ||
|
||
shortKey.Press(shiftValue, speedTyper); | ||
longKey.Press(shiftValue, speedTyper); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# MorseKeyboard_CircuitPlaygroundExpress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
class KeyboardKey { | ||
int keyPin; // the number of the button pin | ||
char modifierValue; | ||
char keyValue; | ||
char letterValue; | ||
char altLetterValue; | ||
int pressSpeed; | ||
int debounceDelay; | ||
int freq; | ||
int sndLength; | ||
int sndPin; | ||
bool buttonTriggerState; | ||
|
||
bool keyFirstPress = true; | ||
|
||
unsigned long lastDebounceTime = 0; | ||
|
||
public: | ||
KeyboardKey (int pin, char primaryKeyValue, char secondaryKeyValue, int debouncerTime, int speakerPin, int freqValue, int sndDuration, bool buttonValueState) | ||
{ | ||
keyPin = pin; | ||
letterValue = primaryKeyValue; | ||
altLetterValue = secondaryKeyValue; | ||
keyValue = letterValue; | ||
debounceDelay = debouncerTime; | ||
freq = freqValue; | ||
sndLength = sndDuration; | ||
sndPin = speakerPin; | ||
buttonTriggerState = buttonValueState; | ||
int resistorType; | ||
|
||
if (buttonTriggerState == LOW){ | ||
resistorType = INPUT_PULLUP; | ||
} | ||
else{ | ||
resistorType = INPUT_PULLDOWN; | ||
} | ||
|
||
pinMode(keyPin, resistorType); | ||
} | ||
|
||
void Press(boolean isShiftPressed, int ditdahTimer) | ||
{ | ||
int keyState = digitalRead(keyPin); | ||
bool shiftCheck = isShiftPressed; | ||
int playLength = sndLength - pressSpeed; | ||
pressSpeed = ditdahTimer; | ||
|
||
if (isShiftPressed) { | ||
keyValue = altLetterValue; | ||
} | ||
else { | ||
keyValue = letterValue; | ||
} | ||
|
||
if (keyState == buttonTriggerState) { | ||
if (millis() - lastDebounceTime > debounceDelay) { | ||
if (keyFirstPress == true) { | ||
tone(sndPin, freq, playLength / 3); | ||
Keyboard.press(keyValue); | ||
Keyboard.release(keyValue); | ||
keyFirstPress = false; | ||
lastDebounceTime = millis(); | ||
} | ||
while (digitalRead(keyPin) == buttonTriggerState && millis() - lastDebounceTime > debounceDelay) { | ||
if (millis() - lastDebounceTime > pressSpeed) { | ||
tone(sndPin, freq, playLength / 3); | ||
Keyboard.press(keyValue); | ||
Keyboard.release(keyValue); | ||
lastDebounceTime = millis(); | ||
} | ||
} | ||
lastDebounceTime = millis(); | ||
} | ||
} | ||
else { | ||
keyFirstPress = true; | ||
} | ||
} | ||
}; | ||
|
||
class AccessKey { | ||
int keyPin; // the number of the button pin | ||
char keyValue; | ||
int debounceDelay; | ||
bool buttonTriggerState; | ||
|
||
unsigned long lastDebounceTime = 0; | ||
|
||
bool lastButtonState = HIGH; | ||
bool buttonState; | ||
|
||
bool modifierState = false; | ||
|
||
public: | ||
AccessKey (int pin, int debouncerTime, bool buttonStateValue) | ||
{ | ||
keyPin = pin; | ||
debounceDelay = debouncerTime; | ||
buttonTriggerState = buttonStateValue; | ||
|
||
int resistorValue; | ||
|
||
if (buttonTriggerState == LOW){ | ||
resistorValue = INPUT_PULLUP; | ||
} | ||
else{ | ||
resistorValue = INPUT_PULLDOWN; | ||
} | ||
pinMode(keyPin, INPUT_PULLDOWN); | ||
} | ||
|
||
void Press() | ||
{ | ||
int keyState = digitalRead(keyPin); | ||
|
||
if (keyState == buttonTriggerState) { | ||
if (millis() - lastDebounceTime > debounceDelay) { | ||
Keyboard.press(131); | ||
Keyboard.press(176); | ||
Keyboard.releaseAll(); | ||
Keyboard.press(131); | ||
Keyboard.press(176); | ||
Keyboard.releaseAll(); | ||
Keyboard.press(131); | ||
Keyboard.press(176); | ||
Keyboard.releaseAll(); | ||
lastDebounceTime = millis(); | ||
} | ||
lastDebounceTime = millis(); | ||
} | ||
} | ||
|
||
boolean Check() | ||
{ | ||
int keyState = digitalRead(keyPin); | ||
|
||
if (keyState != lastButtonState) { | ||
lastDebounceTime = millis(); | ||
} | ||
|
||
if ((millis() - lastDebounceTime) > debounceDelay) { | ||
if (keyState != buttonState) { | ||
buttonState = keyState; | ||
|
||
if (buttonState == HIGH) { | ||
modifierState = !modifierState; | ||
Keyboard.press(131); | ||
Keyboard.press(176); | ||
Keyboard.releaseAll(); | ||
Keyboard.press(131); | ||
Keyboard.press(176); | ||
Keyboard.releaseAll(); | ||
Keyboard.press(131); | ||
Keyboard.press(176); | ||
Keyboard.releaseAll(); | ||
} | ||
} | ||
} | ||
lastButtonState = keyState; | ||
return modifierState; | ||
} | ||
}; |