Skip to content

Instantly share code, notes, and snippets.

@jh3y
Created November 11, 2019 23:41
Show Gist options
  • Save jh3y/2b1585c45f00bab3dfac3f0f0dcd594e to your computer and use it in GitHub Desktop.
Save jh3y/2b1585c45f00bab3dfac3f0f0dcd594e to your computer and use it in GitHub Desktop.
Morse code player
/**
* 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