Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| /* | |
| 2 serial port test. Put the Arduino analogReadSerial sketch | |
| on two Arduinos and connect them to your computer using 2 | |
| USB ports. Note the port names and change firstPort and | |
| secondPort below to match. Then run this sketch. You should see | |
| data coming in from both ports independently. | |
| */ | |
| var serial1 = new p5.SerialPort(); | |
| var serial2 = new p5.SerialPort(); | |
| var firstPort = '/dev/cu.usbmodem14111'; | |
| var secondPort = '/dev/cu.usbmodem141431'; | |
| var input1 = ''; | |
| var input2 = ''; | |
| function setup() { | |
| createCanvas(400, 300); | |
| serial1.on('data', serialEvent); | |
| serial1.on('error', serialError); | |
| serial2.on('data', serial2Event); | |
| serial2.on('error', serial2Error); | |
| serial1.open(firstPort); | |
| serial2.open(secondPort); | |
| } | |
| function draw() { | |
| background(0x23, 0x76, 0xF3); | |
| fill(255); | |
| text("data from serial port 1:" + input1, 30, 30); | |
| text("data from serial port 2: " + input2, 30, 90); | |
| } | |
| function serialEvent(){ | |
| data = serial1.readStringUntil('\r\n'); | |
| if (data.length > 0){ | |
| input1 = data; | |
| } | |
| } | |
| function serialError(err) { | |
| println("error with serial port 1: " + err); | |
| } | |
| function serial2Event() { | |
| var data = serial2.readStringUntil('\r\n'); | |
| if (data.length > 0){ | |
| input2 = data; | |
| } | |
| } | |
| function serial2Error(err) { | |
| println("error with serial port 2: " + err); | |
| } |