We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Help with text()
Page Index Toggle Pages: 1
Help with text() (Read 508 times)
Help with text()
May 25th, 2009, 9:43am
 
I am trying to display a double which is coming from my Arduino but everytime the variable updates the old value still stays on the screen.

Code:
import cc.arduino.*;
import processing.serial.*;

double temperature;
Arduino arduino;
int tempPin = 0;

PFont myFont;

void setup () {
 size(600, 200);
 println(Arduino.list());
 arduino = new Arduino(this, Arduino.list()[0]);
 arduino.pinMode(tempPin, Arduino.INPUT);
 myFont = createFont("HelveticaNeue", 48);
 textFont(myFont);
}

void draw(){
 if(arduino.analogRead(tempPin)==0)
 {
   System.out.println("Loading..");
   delay(5000);
 }
 float temperature = Thermister(arduino.analogRead(tempPin));
 text("Temperature: " + temperature, 35, 185);
}

float Thermister(int RawADC) {
float Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15;            // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
if ( Temp > 0 )
  {return float(floor(Temp * 100))/100;}
else
  {return float(ceil(Temp * 100))/100;}
}


I would post a screenshot, but I don't have enough posts.

Anyone know why this would be?

Thanks,
Matt
Re: Help with text()
Reply #1 - May 25th, 2009, 10:22am
 
At the being of the draw() method you need to clear the screen before drawing text etc.

Place the following lines at the beginning of the draw function and see what happens. I think thiis will solve your problem. Smiley


Code:

void draw() {
  background(0); // black background
  fill(0,255,0);   // green text
  noStroke();
  // your code
}
Re: Help with text()
Reply #2 - May 25th, 2009, 10:26am
 
Fantastic. Thanks for your help.
Page Index Toggle Pages: 1