hi,
I am using p5 serial library, everything works fine but the only thing is I am unable to close the port once done using it. The browser once opened will not close the port so I wanted to use keypressed() function to close the port when ESCAPE key is pressed. But it is not working. I get the message in console that it is close but it is not closed(another terminal says port is busy). In order to close I had to use the p5 serial port monitor.
The following is the code:
let serial;
var pot;
function setup() {
createCanvas(400, 400);
serial = new p5.SerialPort();
serial.list();
serial.open("COM3");
serial.on('data', portData);
serial.on('close', portClose);
}
function draw(){
background("#2C2323");
fill("#4293D8");
ellipse(width/2, height/2, pot, pot);
}
function portData() {
pot = Number(serial.readLine());
//console.log(pot);
}
function portClose(){
print("Serial Port is Closed");
}
function keyPressed() {
if (keyCode === ESCAPE) {
portClose();
}
}
how can I close the port with key pressed or button would be helpful.
thanks