xxxxxxxxxx
28
let position;
let mass = 50;
let connectButton;
function setup() {
createCanvas(640, 360);
noFill();
// Initialize position of the ellipse
position = createVector(width / 2, height / 2);
// Create a button for serial connection
connectButton = createButton('Connect to Serial');
connectButton.position(10, 10);
connectButton.mousePressed(setUpSerial); // Trigger serial setup on button press
}
function draw() {
background(255);
// Map potentiometer value to horizontal position
position.x = map(potValue, 0, 1023, 0, width);
// Keep the ellipse in the middle of the canvas vertically
ellipse(position.x, height / 2, mass, mass);
fill(255);
}