How do i split??
in
Core Library Questions
•
1 year ago
I need to split into pieces the inString that im receiving but i dont know how, im working with an arduino and processing.
import processing.serial.*;
Serial myPort; //the serial port you're using
String portnum;
String outString="";
String inString="";
int receivedLines=0;
int bufferedLines=10;
void setup()
{
size(400,300);
PFont myFont=createFont(PFont.list()[2],14);
textFont(myFont);
println(Serial.list());
portnum=Serial.list()[0];
myPort=new Serial(this,portnum,9600);
}
void draw()
{
background(0);
/*text("Serial port:"+portnum,10,20);
text("typed:"+outString,10,40);*/
text("received:\n"+inString,10,20);
delay(1000);
}
void keyPressed()
{
switch(key)
{
case '\n':
myPort.write(outString+"\r");
// outString="";
break;
case 8:
outString=outString.substring(0,outString.length()-1);
break;
case '+':
myPort.write(key);
outString+=key;
break;
case 65535:
break;
default:
outString+=key;
break;
}
}
void serialEvent(Serial myPort)
{
int inByte=myPort.read();
inString+=char(inByte);
if(inByte=='\r')
{
inString+='\n';
// inString="";
receivedLines++;
if(receivedLines>bufferedLines)
{ deleteFirstLine(); }
}
}
void deleteFirstLine()
{
int firstChar=inString.indexOf('\n');
inString=inString.substring(firstChar+1);
}
1