xxxxxxxxxx
66
var serial; // variable to hold an instance of the serialport library
var portName = '/dev/tty.usbmodem14601'; // fill in your serial port name here
var cSize = 10; // size of the circle
function setup() {
createCanvas(800, 600);
serial = new p5.SerialPort(); // make a new instance of the serialport library
serial.on('list', printList); // set a callback function for the serialport list event
serial.on('connected', serverConnected); // callback for connecting to the server
serial.on('open', portOpen); // callback for the port opening
serial.on('data', serialEvent); // callback for when new data arrives
serial.on('error', serialError); // callback for errors
serial.on('close', portClose); // callback for the port closing
//serial.list(); // list the serial ports
serial.open(portName); // open a serial port
}
function draw() {
background("#2277A3"); // set the background color
fill("#55CAFE"); // set the circle fill color
noStroke(); // don't use a stroke around the circle
// draw the circle:
ellipse(width/2, height/2, cSize, cSize);
}
function serialEvent() {
var data = serial.read();
// if (data.length > 0) {
// // console.log(data);
// var sensors = split(data, ",");
// console.log(sensors);
// xPos = int(sensors[0]);
// yPos = int(sensors[1]);
cSize = int(data);
}