xxxxxxxxxx
39
var serial;
var portName = "Jeff";
function setup() {
serial = new p5.SerialPort();
serial.on('list', printList); // set a callback function for the serialport list event
serial.on('data', serialEvent); // callback for when new data arrives
createCanvas(400, 400);
}
function draw() {
background(0, 0, 120);
}
// get the list of ports:
function printList(portList) {
// portList is an array of serial port names
for (var i = 0; i < portList.length; i++) {
// Display the list the console:
if (portList[i].indexOf('usbmodem') != -1) {
portName = portList[i];
console.log("Using " + portName + " for serial");
serial.open(portName);
}
console.log(i + " " + portList[i]);
}
}
function serialEvent() {
console.log(serial.read());
// var ln = serial.readLine();
// if (ln.length > 0 ) {
// console.log(ln);
// } else {
// //console.log(".");
// }
}