xxxxxxxxxx
41
let ellipseX = 0; //x value of ellipse to be changed by potentiometer
let B =0;
function setup() {
createCanvas(640, 480);
ellipseMode(CENTER);
}
function draw() {
clear();
background(0)
fill(255,0,B);
ellipse(ellipseX, height/2, 50, 50);
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
// Print the current values
text('ellipseX = ' + str(ellipseX), 20, 50);
}
}
function keyPressed() {
if (key == " ") {
setUpSerial(); //establish serial communication
}
}
function readSerial(data) {
if (data) { //run only if data is received
data = data.trim(); // Remove any whitespace
if (!isNaN(data)) { //check whether data is a number or not
//debug: console.log("Received:", data);
ellipseX = int(data);
}
}
}