xxxxxxxxxx
51
let change = 0;
let previousX;
let previousY;
function setup() {
createCanvas(640, 480);
textSize(18);
textAlign(CENTER);
previousX = 0;
previousY = 0;
}
function draw() {
background('red');
if (!serialActive) {
fill('white');
text("Press Space Bar to select Serial Port", width/2, height/2);
} else {
fill('white');
rectMode(CENTER);
rect(mouseX, mouseY, 200,200);
// fill('black');
// text("Move this to control the brightness of the LED", width/2,height/2);
// getChange();
}
}
function getChange(){
change = floor(sqrt(pow((mouseX - previousX),2) + pow((mouseY - previousY),2)));
previousX = mouseX;
previousY = mouseY;
}
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) {
console.log("here");
writeSerial("100\n");
}