xxxxxxxxxx
27
function setup() {
createCanvas(400, 400);
}
function draw() {
background(225);
// brightness based on cursor's x position
let brightness = map(mouseX, 0, width, 0, 255);
brightness = constrain(brightness, 0, 255); // Ensure brightness stays within range
// Send brightness value to Arduino if serial is active
if (serialActive) {
writeSerial(`${brightness}\n`);
}
}
function keyPressed(){
if (key == " ") { //set up serial
setUpSerial();
}
}
function readSerial(value) {
potValue = int(value); // Parse the potentiometer value
}