Created
April 13, 2016 01:16
-
-
Save jay3686/d47e6e0a229e048f5b8f974a5df7b509 to your computer and use it in GitHub Desktop.
Converts text to dots and dashes
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
var morse = require('morse-node').create("ITU"); | |
var five = require("johnny-five"); | |
var board = new five.Board(); | |
board.on("ready", function() { | |
var led = new five.Led(11); | |
// "blink" the led in 500ms on-off phase periods | |
var s = morse.encode('hello world'); | |
//var s = morse.encode('SOS'); | |
var i = 0 | |
function next() { | |
if(i >= s.length) { | |
return; | |
} | |
led.off(); | |
if (s[i] == '-') { | |
setTimeout(function(){ | |
i += 1 | |
led.on(400); | |
setTimeout(next, 400); | |
}, 400) | |
//led.off(); | |
} | |
else if (s[i] == '.') { | |
setTimeout(function(){ | |
i += 1 | |
led.on(200); | |
setTimeout(next, 200); | |
}, 200) | |
//led.off(); | |
} | |
else { | |
led.off(); | |
i += 1 | |
setTimeout(next, 200); | |
} | |
} | |
console.log('start'); | |
next(); | |
console.log('done'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment