Ich habe noch mal am Kommunikationszeugs mit Processing herumgebastelt (bzw. eingefügt was du mir gesagt hasst XD)
jetzt habe ich aber noch das Problem, dass ich, wenn ich den delay() im void draw() von Processing unter 500 setze, funktioniert gar nichts mehr.. weshalb ist denn das so?!
hier die Codes:
Processing:
import processing.serial.*;
Serial myPort;
int firstValue, secondValue;
void setup()
{
size (500, 500);
println(Serial.list());
myPort = new Serial(this, "/dev/tty.usbmodem1411", 9600);
}
void draw()
{
background(51);
int led1 = mouseX;
int led2 = mouseY;
myPort.write(str(led1));
myPort.write(",");
myPort.write(str(led2));
myPort.write(",");
myPort.write("\r");
text(firstValue, 10, 30);
text(secondValue, 10, 60);
delay(500);
}
void serialEvent(Serial myPort)
{
if (myPort.available() > 0)
{
String completeString = myPort.readStringUntil(10);
if (completeString != null)
{
trim(completeString);
String seperateValues[] = split(completeString, ',');
firstValue = int(seperateValues[0]);
secondValue = int(seperateValues[1]);
}
}
}
und der Arduino:
const int SERIAL_BUFFER_SIZE = 31;
char serialBuffer[SERIAL_BUFFER_SIZE];
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(readSerial() == true)
{
Serial.print(serialBuffer);
Serial.print(',');
Serial.println();
}
}
bool readSerial()
{
static byte index;
if(Serial.available() > 0)
{
char c = Serial.read();
if(c >= 32 && index < SERIAL_BUFFER_SIZE - 1)
{
serialBuffer[index++] = c;
}
else if(c == '\r')
{
serialBuffer[index] = '\0';
index = 0;
return true;
}
}
return false;
}
wäre mal wieder Dankbar um Hilfe XD
LG