I am showing text in a window but instead of showing my number it just shows “Humidity: null%”
Here is my code:
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
int xPos = 1; //horizontal position of graph
float inByte = 0;
PFont f;
void setup()
{
size(1080, 720); //Window size (length, height)
f = createFont("Helvetica", 16, true); // Helvetica, 16 point, anti-aliasing on
myPort = new Serial(this, "COM3", 9600); //port #
myPort.bufferUntil('\n'); //don't generate a serialEvent() unless you get a newline character
background (0);
}
void draw()
{
stroke(127, 34, 255); //draw the line
line(xPos, height, xPos, height - inByte);
//at the edge of the screen, go back to the beginning
if (xPos >= width) {
xPos = 0;
background(0);
} else {
//increment horizontal position
xPos ++;
}
textFont(f, 24);
fill(127, 34, 255);
text("Humidity:", 20, 44);
String humidityText="Humidity: " + val + "%";
text(humidityText,20,44);
}
void serialEvent (Serial myPort) {
//get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
//trim off any white space
inString = trim(inString);
//convert to an int and map to the screen height
inByte = float(inString);
println(inByte);
inByte = map(inByte, 0, 1023, 0, (height*7));
}
}
I’m pretty sure the issue is in this line: String humidityText="Humidity: " + val + "%";
.
Am I using the wrong variable? Or is what I’m trying to do not possible?
Thank you for the help.