did you check on how to use CP5 Textarea
i not see any
myTextarea.setText("test");
try like
// https://discourse.processing.org/t/port-serial-en-size/7568
// v01 2 cp5 button and 2 text()
// v02 instead text() 3 cp5 textarea ( in, out, console )
// http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5textarea/ControlP5textarea.pde
// https://github.com/sojamo/controlp5/blob/master/examples/extra/ControlP5console/ControlP5console.pde
import controlP5.*; //import ControlP5 library
ControlP5 cp5; //create cp5 object
Textarea inTXT, outTXT, sysTXT;
Println console;
import processing.serial.*;
Serial port;
String portName;
boolean serOn = true;//false;//true;
PFont font;
String outtxt="we send:";
String intxt="we got:";
void setup() {
size(800, 500); //window size, (width, height)
font = createFont("calibre light bold", 20);
setup_communication();
setup_buttons();
println("key [c] clear");
}
void draw() { //same as loop in arduino ide
background(150, 200, 200); // background color of window (r, g, b) or (0 to 255)
instream();
fill(25, 115, 235); //text color (r, g, b)
text("SERIAL PORT "+portName, 100, 30); //lets give title to our window
}
void setup_communication() {
printArray(Serial.list()); //prints all available serial ports
portName = Serial.list()[1]; // change the [1] acc the list you got printed
println("try connect to "+portName);
if (serOn) port = new Serial(this, portName, 9600);
}
void setup_buttons() {
//so when you press any button on the GUI, it sends particular char over serial port
cp5 = new ControlP5(this);
cp5.addButton("A")
.setPosition(30, height-70) //x and y coordinates of upper left corner of button
.setSize(60, 60) //(width, height)
.setFont(font);
cp5.addButton("B")
.setPosition(130, height-70) //x and y coordinates of upper left corner of button
.setSize(60, 60) //(width, height)
.setFont(font);
int tposX=20, tposY=40, tw=width-40, th=100;
outTXT = cp5.addTextarea("outtxt")
.setPosition(tposX, tposY)
.setSize(tw, th)
.setFont(createFont("arial", 12))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(255, 100))
.setColorForeground(color(255, 100));
;
outTXT.setText(outtxt);
tposY += th+10;
th = 200; // move down
inTXT = cp5.addTextarea("intxt")
.setPosition(tposX, tposY)
.setSize(tw, th)
.setFont(createFont("arial", 12))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(200, 200, 0, 100))
.setColorForeground(color(255, 100));
;
inTXT.setText(intxt);
tposY += th+10;
th = 60; // move down
sysTXT = cp5.addTextarea("systxt")
.setPosition(tposX, tposY)
.setSize(tw, th)
.setFont(createFont("arial", 12))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(200, 0, 0, 100))
.setColorForeground(color(255, 100));
;
console = cp5.addConsole(sysTXT);
}
void A() {
if (serOn) port.write('A');
println("send A"); //_______add kll
outtxt += "\nA";
outTXT.setText(outtxt);
}
void B() {
if (serOn) port.write('B');
println("send B"); //_______add kll
outtxt += "\nB";
outTXT.setText(outtxt);
}
void instream() {
if ( serOn && port.available() > 0) { // If data is available,
int inByte = port.read(); // read it and store it in intxt
if ( inByte == 10 ) intxt += "\n";
else intxt += str(inByte);
inTXT.setText(intxt);
}
}
void keyPressed() {
if ( key == 'c' ) {
intxt = "";
inTXT.setText(intxt);
outtxt = "";
outTXT.setText(outtxt);
}
}