xxxxxxxxxx
41
let right = 0;
function setup() {
createCanvas(255,255);
textSize(18);
}
function draw() {
background(0,0,mouseX);
fill(255);
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
text(mouseX, 20, 50);
}
right = mouseX;
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
//////////////////////////////////
//SEND TO ARDUINO HERE (handshake)
//////////////////////////////////
let sendToArduino = right + "\n";
writeSerial(sendToArduino);
}