xxxxxxxxxx
28
let circlePosition = 100;
function setup() {
createCanvas(400, 400);
textSize(18);
fill(243,213,205);
text("Press the space bar to connect port", width / 2, 60);
}
function draw() {
background(176, 16, 50);
textSize(18);
fill(243,213,205);
text("Press the space bar to connect port", 60, 60);
ellipse(circlePosition, height / 2, 70, 70);
}
// Function to set up the serial connection
function keyPressed() {
if (key == " ") {
setUpSerial();
}
}
// Function to read the data from serial port
function readSerial(data) {
// Check if data received is not null
if (data != null) {
// Mapping the data to 0-400 and sets it as X position of the circle
circlePosition = map(int(data), 0, 1023, 0, 400);
}
}