xxxxxxxxxx
70
const pts = []
var size = 0.6;
let rVal = 0;
let alpha = 255;
let left = 0;
let right = 0;
var img0;
mode = 0;
function preload () {
img0 = loadImage("worldmap1.svg");
}
function setup() {
createCanvas(innerWidth, innerHeight);
pixelDensity(5);
textSize(18);
setUpSerial();
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial(SELECT_PORT);
}
}
function draw() {
if (mode== 0) {
image(img0, 0, 0, width, height);
}
// background(map(rVal, 0, 1023, 0, 255), 255, 255);
console.log(rVal)
fill(100);
stroke(255);
strokeWeight(1);
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
}
}
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 == 1) {
// only store values here
// do everything with those values in the main draw loop
rVal = fromArduino[0];
}
//////////////////////////////////
//SEND TO ARDUINO HERE (handshake)
//////////////////////////////////
let sendToArduino = "\n";
writeSerial(sendToArduino);
}
}