xxxxxxxxxx
80
// TEST ONLY
let reset = 0;
let x = 0;
let y = 0;
let z = 0;
let r = 0;
let g = 0;
let b = 0;
let px = 0;
let py = 0;
let eraserMode = 0;
let displayAccessoryMode = 0;
function setup() {
createCanvas(600, 360);
textAlign(CENTER,CENTER);
}
function draw() {
background(235);
if (!serialActive) {
console.log("Press Space Bar to select Serial Port");
} else {
// console.log("Connected");
}
text("Position: ["+x+","+y+","+z+"]",width/2,150);
text("Color: ["+r+","+g+","+b+"]",width/2,160);
text("Perspective: ["+px+","+py+"]",width/2,170);
text("Eraser: "+eraserMode,width/2,180);
text("Display: "+displayAccessoryMode,width/2,190);
}
function keyPressed() {
// Only SPACEBAR, which is used to setup serial remains.
// All other keyboard interaction are removed
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
function readSerial(data) {
////////////////////////////////////
//READ FROM ARDUINO HERE
////////////////////////////////////
if (data != null) {
// make sure there is actually a message
// split the message
let fromArduino = split(trim(data), ",");
// if the right length, then proceed
if (fromArduino.length == 10) {
// only store values here
// do everything with those values in the main draw loop
x = fromArduino[0];
y = fromArduino[1];
z = fromArduino[2];
r = fromArduino[3];
g = fromArduino[4];
b = fromArduino[5];
px = fromArduino[6];
py = fromArduino[7];
eraserMode = fromArduino[8];
displayAccessoryMode = fromArduino[9];
}
//////////////////////////////////
//SEND TO ARDUINO HERE (handshake)
//////////////////////////////////
let sendToArduino = reset + "\n";
writeSerial(sendToArduino);
}
}
//Arudino Code