Open the js Part!
<br/> and also call the checkPort() in p5!
let inString = serial.readStringUntil("\r\n");
// print(inString);
//check to see that there's actually a string there:
if (inString) {
let sensors = split(inString, ",");
console.log(sensors);
if(sensors[0]=="p0"){
// ball.x = int(map(sensors[1], 0, 200, 0, 200));
value0= sensors[1];
// console.log(sensors[0]);
}
if(sensors[0]=="p1"){
// ball.y = int(map(sensors[1], 0, 200, 0, 200));
value1=sensors[1];
// console.log(sensors[0]);
}
if(sensors[0]=="p2"){
// ball.y = int(map(sensors[1], 0, 200, 0, 200));
value2=sensors[1];
// console.log(sensors[0]);
}
}
}
/////////////////////////////////////////////
// UTILITY FUNCTIONS TO MAKE CONNECTIONS ///
/////////////////////////////////////////////
// if there's no port selected,
// make a port select button appear:
function makePortButton() {
// create and position a port chooser button:
portButton = createButton("choose port");
portButton.position(10, 10);
// give the port button a mousepressed handler:
portButton.mousePressed(choosePort);
}
// make the port selector window appear:
function choosePort() {
serial.requestPort();
}
// open the selected port, and make the port
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.