Skip to content

Instantly share code, notes, and snippets.

@jay3686
Created April 13, 2016 01:16
Show Gist options
  • Save jay3686/d47e6e0a229e048f5b8f974a5df7b509 to your computer and use it in GitHub Desktop.
Save jay3686/d47e6e0a229e048f5b8f974a5df7b509 to your computer and use it in GitHub Desktop.
Converts text to dots and dashes
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