Skip to content

Instantly share code, notes, and snippets.

@alx
Created April 6, 2012 16:14
Show Gist options
  • Select an option

  • Save alx/2321060 to your computer and use it in GitHub Desktop.

Select an option

Save alx/2321060 to your computer and use it in GitHub Desktop.
Ledpong : random with nodejs
var SerialPort = require("serialport").SerialPort;
var serialPort;
try {
serialPort = new SerialPort("/dev/ttyACM0", { baudrate: 38400 });
} catch(e) {
console.error(e.stack);
serialPort = { write: console.log };
}
setInterval(function() {
var random = "Z";
for(i=0; i<432; i++){
var num = Math.random();
if(num > 0.8){
random += "F";
} else if(num > 0.6){
random += "A";
} else if(num > 0.4){
random += "6";
} else if(num > 0.2){
random += "3";
} else {
random += "0"
}
}
serialPort.write(random);
}, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment