xxxxxxxxxx
45
let brightness = 0;
function setup() {
createCanvas(640, 480);
textSize(18);
slider = createSlider(0, 255);
slider.position(width/2, height/2);
slider.size(80);
}
function draw() {
background('white')
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
}
text("brightness: " + str(brightness), 150, height/2+15);
brightness = slider.value();
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
let sendToArduino = brightness + "\n";
writeSerial(sendToArduino);
}