Created
November 11, 2019 23:41
-
-
Save jh3y/2b1585c45f00bab3dfac3f0f0dcd594e to your computer and use it in GitHub Desktop.
Morse code player
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
/** | |
* Teach a user morse code | |
*/ | |
g.clear() | |
let index = 0; | |
const MORSE_MAP = { | |
a: '.-', | |
b: '-...', | |
c: '-.-.', | |
d: '-..', | |
e: '.', | |
f: '..-.', | |
g: '--.', | |
}; | |
const chars = MORSE_MAP[Object.keys(MORSE_MAP)[2]].split('') | |
const beepItOut = (index) => { | |
E.showMessage(chars[index]) | |
Bangle.beep(chars[index] === '.' ? 100 : 1000) | |
.then(() => { | |
if (chars[index + 1]) { | |
setTimeout(() => {beepItOut(index + 1)}, 500) | |
} else { | |
Bangle.buzz() | |
} | |
}) | |
} | |
beepItOut(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment