Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
56 lines (46 sloc)
1.29 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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); | |
| } |