Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var serial;
- var portName = '/dev/cu.usbmodem14101';
- var sensor1 = 0;
- var sensor2 = 0;
- function setup() {
- createCanvas(100, 600);
- serial = new p5.SerialPort();
- serial.on('connected', serverConnected);
- serial.on('open', portOpen);
- serial.on('error', serialError);
- serial.on('close', portClose);
- serial.open(portName);
- }
- function draw() {
- background('dodgerblue');
- noStroke();
- ellipse(width/2, height/2, sensor1, sensor2);
- }
- function mouseDragged(){
- var outputVal = Math.floor(map(mouseY, 0, height, 0, 255));
- print(outputVal);
- serial.write(outputVal);
- }
- function serverConnected(){
- console.log('connected to the server');
- }
- function portOpen(){
- console.log('the serial port opened!');
- }
- function serialError(err){
- console.log('something went wrong with the port. ' + err);
- }
- function portClose(){
- console.log('the port was closed');
- }
- function printList(portList) {
- for (var i = 0; i < portList.length; i++) {
- print(i + " " + portList[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement