xxxxxxxxxx
35
let brightnessValue = 0;
function setup() {
createCanvas(640, 480);
textSize(18);
}
function draw() {
background(250);
//setting up the serial port information
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
//depending on where the mouse is from left to right, sending that value as a brifghtness value to arduino
brightnessValue = int(map(mouseX, 0, width, 0, 255));
text('Brightness: ' + str(brightnessValue), 20, 50);
let sendToArduino = brightnessValue + "\n";
//printing that value in serial monitor arduino
writeSerial(sendToArduino);
}
}
function keyPressed() {
if (key == " ") {
setUpSerial();
}
}
function readSerial(data) {
//just to avoid no readSerial error saving data
if (data != null) {
let receivedData = data
}
}