xxxxxxxxxx
29
let serial; // variable to hold an instance of the serialport library
let portName = '/dev/tty.usbserial-1410'; // fill in your serial port name here
let inData,outData;
function setup() {
createCanvas(300,300);
serial = new p5.SerialPort();
serial.on('data', serialEvent);
serial.on('error', serialError);
serial.open(portName);
}
function draw(){
background(200);
outData=map(mouseY,0,height,0,255)
serial.write(outData);
fill(255);
textSize(30);
text("incoming value: " + inData, 10, 30);
}
function serialEvent() {
inData=serial.read();
}
function serialError(err) {
console.log('Something went wrong with the serial port. ' + err);
}