xxxxxxxxxx
39
let potValue = 0;
let serialInitialized = false;
function setup() {
createCanvas(420, 400);
ellipseMode(CENTER);
}
function draw() {
background(0);
// move the ellipse based on the potentiometer values
xPos = map(potValue, 0, 1023, 0, width);
fill(255);
ellipse(xPos, height / 2, 50, 50);
}
function keyPressed() {
if (key === ' ') {
if (!serialInitialized) {
setUpSerial();
serialInitialized = true;
}
}
}
async function setUpSerial() {
noLoop();
await getPort();
serialActive = true;
runSerial();
loop();
}
function readSerial(value) {
potValue = int(value);
}