# Trouble with variable as text on screen

**URL:** <https://discourse.processing.org/t/trouble-with-variable-as-text-on-screen/6333>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 5, 2018, 4:34pm UTC](https://discourse.processing.org/t/trouble-with-variable-as-text-on-screen/6333 "2018-12-05T16:34:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Banansplitt](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Banansplitt](https://discourse.processing.org/u/Banansplitt)\
**Post date:** [December 5, 2018, 4:34pm UTC](https://discourse.processing.org/t/trouble-with-variable-as-text-on-screen/6333/1 "2018-12-05T16:34:31Z")

</div>

I am showing text in a window but instead of showing my number it just shows “Humidity: null%”  
Here is my code:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [December 5, 2018, 5:36pm UTC](https://discourse.processing.org/t/trouble-with-variable-as-text-on-screen/6333/2 "2018-12-05T17:36:05Z")

</div>

You’re never setting the `val` variable?
