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 & HelpPrograms › Trying to create a temperature profiler with UI
Pages: 1 2 
Trying to create a temperature profiler with UI (Read 3562 times)
Re: Trying to create a temperature profiler with UI
Reply #15 - Aug 18th, 2009, 10:35pm
 
ben, I really appreciate your help.  i'm getting there.  but I think I just need to see a full sketch to pound it through.  I've been searching like mad trying to find something similar to help me learn, but having a hard time.  Do you have a link where I could see a full code?
Maybe something with just a few values?

Thats how I've built my first sketch that I've listed here.
Re: Trying to create a temperature profiler with UI
Reply #16 - Aug 19th, 2009, 8:17am
 
Ok.  This is essentially the sample code from my first reply.

Quote:
int numberOfGraphPoints=640; // match width for simplicity in demo
float[] tempValsA = new float[numberOfGraphPoints]; // initialize 1st array
float[] tempValsB = new float[numberOfGraphPoints]; // initialize 2nd array
int currentPoint=0; // the marker used to travel through the array.
float randomTempA, randomTempB; // these stand in for your data.
int previousGrabTime=0, timeStep=1; // low timestep for fast demo

void setup(){
  size(640,480);
  background(255); // white
  randomTempA = random(200,300); // starting value
  randomTempB = random(200,300); // starting value
  currentPoint=0; // reset array marker
  println("generating random values..."); // output to console for demo
}

void draw(){
  if (currentPoint < numberOfGraphPoints){ // don't exceed your arrays
    if (millis() - previousGrabTime >= timeStep){ // if it's time to grab
      println("generating random values for point " + currentPoint);
      // grab the values for A and B
      // store them in the two float[] arrays
      randomTempA+=random(-2,2); // vary the temperature randomly
      randomTempB+=random(-2,2); // (for the demo)
      tempValsA[currentPoint]=randomTempA; // plug the values into the arrays
      tempValsB[currentPoint]=randomTempB;
      currentPoint++; // add 1 to the current point
      previousGrabTime = millis(); // reset the wait time
    }
  }
  else plot();
}

void plot(){
  println("plotting...");
  stroke(0); // black
  for (int a=0; a<tempValsA.length; a++){
    point(a, tempValsA[a]); // run through the array and plot the points
  }
  stroke(255,0,0); // red
  for (int b=0; b<tempValsB.length; b++){
    point(b, tempValsB[b]); // plot the second array
  }
  noLoop(); // stop the program once finished plotting
}
Re: Trying to create a temperature profiler with UI
Reply #17 - Aug 19th, 2009, 9:20am
 
wow! Thanks, thats perfect.
One stupid question, amongst many.  The "graph points" is the width of the window for the demo.  If i want to graph each second, 1200, I can still do that within a window that is smaller, say 500 width, right?  Just depends how I map it right?
Re: Trying to create a temperature profiler with UI
Reply #18 - Aug 19th, 2009, 1:08pm
 
try it!

good luck!
Re: Trying to create a temperature profiler with UI
Reply #19 - Aug 22nd, 2009, 4:30pm
 
so i used your code and it graphed after the sketch was over.  I would actually like to graph real time.  But any way, could you let me know if this is on the right track.
My graph in the sketch is (500,375), but to build a graph separately for experimenting I'm using the following code at that window size.

with 125 being my lowest desired reading, I came up with the following formula.
y = 375 - (temperature - 125)
for 200 deg F, it would be ... 375-(200-125) = 300  giving me a y value of 300.
with that said, is this code accurate?
is it necessary to have to record 1200 values for each temp? basically typing in 2400 lines of info for the tempvals?

Code:
import processing.serial.*;

int timeStep = 1000;
int previousGrabTime = 0;

Serial commPort;
float tempC;
float tempF;
float tempB;
float tempEnvF;

float tempValsA = new float[1200];
float tempValsB = new float[1200];
int currentPoint = 0;

void setup()
{
 
 commPort = new Serial(this, Serial.list()[1], 9600);
 
 size(500,375);
 background(255);
}
 void draw ()
{
while (commPort.available() > 0)
 {
   tempC = commPort.read();
   tempB = commPort.read();
 
  tempF = ((tempC*9)/5) + 32;
  tempEnvF = ((tempB*9)/5) + 32;
 
 
 
if (currentPoint<1200){
if(millis() - previousGrabTime >= timeStep){  
 
tempValsA[0] = (375-(tempF-125));
tempValsB[0] = (375-(tempEnvF-125));
tempValsA[1] = (375-(tempF-125));
tempValsB[1] = (375-(tempEnvF-125));
tempValsA[2] = (375-(tempF-125));
tempValsB[2] = (375-(tempEnvF-125));

etc.. etc.. up to:
tempValsA[1199] = (375-(tempF-125));
tempValsB[1199] = (375-(tempEnvF-125));


if that is correct, where do I place that code in my sketch?






Re: Trying to create a temperature profiler with UI
Reply #20 - Aug 22nd, 2009, 5:00pm
 
or  
//with
int grabbedDataA = (375-(tempF-125));
int grabbedDataB = (375-(temEnvF-125));
//then
TempValsA[currentPoint] = [grabbedDataA];
TempValsB[currentPoint] = [grabbedDataB];

Re: Trying to create a temperature profiler with UI
Reply #21 - Aug 22nd, 2009, 6:07pm
 
Well, typing almost the same thing 1200 times is never the answer -- that's what for() and while() loops are for.  Try this code in a separate sketch, for example:

for(int i=0; i<10; i++){
 println("Hello world " + i );
}

If it were my project, I'd want my temperature values to stay accurate, in case I wanted to use them in another way later on.  There's really no reason to change the values in your temp. arrays.  Just change how the point(x,y) call uses the temp values.  For instance, if you have a value x, and y, and call:
point(x,y);
you'll get a point at (x,y).  And if you call:
point (x,375-(y-125));
you'll get a point that's at the y-value (375-(y-125)) rather than straight (y).

If you want it to display the points as they're generated, just  comment out the line "else plot()" (by putting // in front of it), and right after the randomTempA and B are generated, insert:
stroke(0); // black
point(currentPoint, randomTempA);
stroke(255,0,0); // red
point(currentPoint, randomTempB);

If you don't have a clear idea of how each line is working, I recommend looking up the functions in reference, and messing with them until it does make sense.

And if you need more help, please reply to my PM (top of the board page, "you have # messages") -- so we don't keep clogging the Exhibition board.

--Ben
Pages: 1 2