Skip to content

Instantly share code, notes, and snippets.

@stefania11
Last active September 10, 2015 12:18
Show Gist options
  • Save stefania11/685c4b9c588eda0afa0c to your computer and use it in GitHub Desktop.
Save stefania11/685c4b9c588eda0afa0c to your computer and use it in GitHub Desktop.
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/cu.usbmodem1411", {
baudrate: 57600
}, false); // this is the openImmediately flag [default is true]
serialPort.open(function (error) {
// more code here//
var regex = /\d+/g;
var port = str.match(regex);
console.log(port);
if(port !== null){
console.log('data received: ' + data);
console.log(str);
if (str.indexOf("was just touched") > -1){
console.log(port[0]);
io.sockets.emit("hit", {'sound': port[0]})
console.log("TOUCH");
}else if (str.indexOf("no longer being") > -1){
console.log("NOPE");
}
//more code here //
});
//general list of ports for debugging//
var serialPorts = require("serialport");
serialPorts.list(function (err, ports) {
ports.forEach(function(port) {
console.log(port.comName);
console.log(port.pnpId);
console.log(port.manufacturer);
});
});
module.exports = app;
console.log("Listening on port " + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment