xxxxxxxxxx
34
let brightness = 0;
let slider;
function setup() {
createCanvas(400, 200);
//make the slider
slider = createSlider(0, 255, 127);
slider.position(10, 10);
slider.style('width', '300px');
let serialButton = createButton("Connect to Arduino");
serialButton.position(10, 50);
serialButton.mousePressed(setUpSerial);
}
//troubleshoot
function readSerial(data) {
console.log("Received data:", data); // Log the received data to the console
}
function draw() {
background(220);
brightness = slider.value();
fill(0);
textSize(16);
text(`LED Brightness: ${brightness}`, 10, 100);
// Send brightness value to Arduino via Serial
if (serialActive) {
writeSerial(brightness + "\n"); // Append a newline character
}
}