Handle received messages from arduino serial port
This commit is contained in:
parent
c62c9c44d1
commit
6bb22a78db
1 changed files with 23 additions and 2 deletions
|
|
@ -1,3 +1,24 @@
|
|||
void setup() {}
|
||||
import processing.serial.*;
|
||||
|
||||
void draw() {}
|
||||
Serial arduinoPort;
|
||||
String receivedMessage;
|
||||
boolean cameIntoThreshhold = false;
|
||||
|
||||
void setup() {
|
||||
String portName = Serial.list()[Serial.list().length - 1]; //change the 0 to a 1 or 2 etc. to match your port
|
||||
arduinoPort = new Serial(this, portName, 9600);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if ( arduinoPort.available() > 0) {
|
||||
String rec = arduinoPort.readStringUntil('\n');
|
||||
if (rec != null) {
|
||||
receivedMessage = rec;
|
||||
}
|
||||
|
||||
// Check for specific events and act upon them
|
||||
if (receivedMessage != null && receivedMessage.contains("isWithinThreshhold")) {
|
||||
cameIntoThreshhold = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue