...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import processing.serial.*; // Import the Processing Serial Library for communicating with arduino Serial myPort; // The used Serial Port int firstValue, secondValue; // fourthValue, fifthValue, ... // add more if needed void setup() { size(500, 500); println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list) myPort = new Serial(this, "/dev/cu.usbmodem12131", 9600); // Open a new port and connect with Arduino at 9600 baud } void draw() { } void serialEvent(Serial myPort) // Is called everytime there is new data to read { if (myPort.available() > 0) { String completeString = myPort.readStringUntil('\n'); // Read the Serial port until there is a linefeed/carriage return if (completeString != null) // If there is valid data insode the String { completeString = trim(completeString); // Remove whitespace characters at the beginning and end of the string String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received if (seperateValues.length == 2) { firstValue = int(seperateValues[0]); secondValue = int(seperateValues[1]); } } } } |
Processing zu Arduino
...