Why does my scale not appear at the second screen?

edited January 2016 in Library Questions

So I'm kinda new to Processing and java and had to programm a plotter, which gets data from an Arduino(connected to a Pirani Gauge), converts to pressure and displays it . When the Graph has ran once trough ( xPos >= width) the programm clears the screen and should draw the scale new but it doesn't. I think I didn't get the Java Structure :D Thank you for your help and have a nice day :)

Here is the Code, you may need an Arduino sending println Strings to execute it

import processing.serial.*;
Serial myPort;       
int xPos = 1;         
float inByte = 0;
float printValue = 0;
PrintWriter output;
int d  =  day();    
int m  =  month();
int y  =  year();   
int h  =  hour();
int mi =  minute();
int value = 0;
int number = 55;
int axis = 0;
int incree = 1;
int increeax = 14;
String Tag     = str(d);
String Monat   = str(m);
String Jahr    = str(y);
String Stunde  = str(h);
String Minute  = str(mi);
String End     = (".txt");
String textValue = "";
void setup () {
fullScreen(); 
String[] Date = new String[6] ;
Date[0] = Tag   ;
Date[1] = Monat ;
Date[2] = Jahr  ; 
Date[3] = Stunde;
Date[4] = Minute;
Date[5] = End;
String DateData = join(Date, ",");
output = createWriter(DateData); 
printArray(Serial.list());
   
   myPort = new Serial(this, Serial.list()[0], 9600);
   myPort.bufferUntil('\n');
   
   background(0);
  
  }
void draw () {
  
  stroke(250, 0, 0);
  line(xPos, height, xPos, height - inByte);
  
  for (int i = 0; i < 1370; i = i+14) {
       stroke(#FFFFFF);
       line(0, i, width, i); 
       textSize(15);
       text(number, 10, axis);
       number -= incree;
       axis += increeax;
      }
      
  output.println(printValue +" mBar" ); 
  printValue = map(inByte, 0, 1023, 0, 10);       //auf pressure ummappen, noch formel einsetzen
  fill(0);
  noStroke();
  rect(0, 0, width, 30);
  fill(#FFFFFF);
  text("Pressure:  " + printValue    + "     mBar", width -600, 25); 
  text("Pirani gauge pressure Analyzer Ver. 1.2  Copyright 2016 L.Ponzio", width - 1300, 25);
  text("Time: " + millis()+ " mSec", width -775, 25);
  text("mBar", width-1350, 25);
  
  if (xPos >= width) {
    xPos = 30;
    background(0);
     } else {
       xPos++;
      }
 }
void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    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);
  }
}
void keyPressed() {
  output.flush();  
  output.close();  
  exit();  
}

`

Answers

Sign In or Register to comment.