Skip to content

Instantly share code, notes, and snippets.

@JonathanMH
Created May 3, 2013 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanMH/5514395 to your computer and use it in GitHub Desktop.
Save JonathanMH/5514395 to your computer and use it in GitHub Desktop.
make node.js blink your keyboard backlight in morse code (tested with speedlink illuminator)
var morse = require('morse');
var childProcess = require('child_process');
var async = require('async');
var encoded = morse.encode('SOS');
function onoff (duration, callback) {
childProcess.exec('xset led 3',function (error, stdout, stderr){
});
setTimeout(function(){
childProcess.exec('xset -led 3',function (error, stdout, stderr){
callback();
});
}, duration);
}
encoded = encoded.replace(/\s+/g, '');
arr = encoded.split('');
function ownlog(item, cb){
if(item == '-'){
duration = 2000;
}
else if(item == '.'){
duration = 500;
}
else {
duration = 0;
cb();
}
onoff(duration,function(){
console.log(item + ' ' + duration);
});
setTimeout(function(){
cb();
},300 + duration);
}
async.eachSeries(arr, ownlog, function(err){
// if any of the saves produced an error, err would equal that error
if (err) throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment