xxxxxxxxxx
32
let serial;
let portName = '/dev/tty.usbserial-1410';
let inDataY,outDataY;
function setup() {
createCanvas(300,300);
serial = new p5.SerialPort();
serial.on('data', serialEvent);
serial.on('error', serialError);
serial.open(portName);
}
function draw(){
background(200);
outDataX=int(map(mouseX,0,width,0,255));
outDataY=int(map(mouseY,0,height,0,255));
serial.write(outDataX+","+outDataY+"\n");
fill(255);
textSize(20);
text("outDataX: " + outDataX, 0, 30);
text("outDataY: " + outDataY, 0, 60);
}
function serialEvent() {
// inDataY=serial.read();
}
function serialError(err) {
console.log('Something went wrong with the serial port. ' + err);
}