xxxxxxxxxx
30
let slider; // slider to control LED brightness
let serial;
function setup() {
serial = new p5.SerialPort();
serial.open("COM4");
createCanvas(400, 400); // create a canvas
slider = createSlider(0, 255, 0); // create a slider
slider.position(50, 50); // set the position of the slider
}
function draw() {
background(220); // clear the canvas
let val = slider.value(); // get the slider value
text("LED Brightness: " + val, 50, 50); // display the brightness value
// send data to Arduino over serial
if (frameCount % 10 == 0) { // limit the rate of sending data to avoid overloading the serial port
serial.write(val); // send the slider value over serial
}
}