We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I wrote a simple interface for the inputs i get via RS-232 from my MCU.
In serialEvent i get the string, check the formatting, and if that's okay, i process it into a value and map to the screen.
In draw i output the received value in text form on the screen. The problem with that is that bytes incoming via RS-232 sometimes interrupt the process of erasing the text with a black box before writing another value on the screen. This results in artifacts like in the picture. How do you suggest i fix that?
void serialEvent(Serial myPort)
{
inString = myPort.readStringUntil('\n');
if (inString != null)
{
inString = trim(inString);
stringSymbol = inString.substring(1, 2);
if (stringSymbol.equals(":"))
{
allowTextF = true;
sS = int(inString.substring(0, 1));
inString = inString.substring(2);
inByte = float(inString);
inByte = displayH - map(inByte, minValue[sS], maxValue[sS], 0, displayH);
stroke(colors[sS]);
line(xPos[sS] - 1, oldValue[sS], xPos[sS], inByte);
oldValue[sS] = inByte;
if (xPos[sS] >= displayW)
{
background(0);
for (int i = 0; i < nSignals; i++)
{
xPos[i] = 1;
}
}
xPos[sS]++;
}
else allowTextF = false;
}
}
void draw()
{
stroke(0);
fill(0);
rect(displayW/2, displayH/2 - sS*(textAscent()+textDescent()), 100, textAscent()+textDescent());
fill(colors[sS]);
if (allowTextF == true)
{
text(inString, displayW/2, displayH/2 - sS*(textAscent()+textDescent()));
}
}
Answers
If draw() is meant to be updated based on serialEvent(), then you should just halt the former w/ noLoop();
and use redraw() & clear() inside the latter! 8-X
It took me a long time to get what you were suggesting, but disabling draw() altogether by putting noLoop() at the end of the setup() and then launching draw() manually with redraw() is a sound advice!