making a comparison multiple times before making a decision

I need some help wrapping my head around how to do this. I am imagining some type of for loop but am unsure on how to implement it. Any help would be appreciated.

Example:
I would like to take multiple dewpoint readings to determine if the dewpoint is dropping over time, say 5 minutes.

Here is my code for determining dewpoint based off temperature and humidity readings.

void getDewPoint(double)
{
  Serial.begin(9600);
  h = htu.readHumidity();
  dt = htu.readTemperature();

  vp=(6.11*pow(10,((7.5*dt)/(237.3+dt))));
  double dp=((237.3*(log((vp*h)/611)))/((7.5*(log(10)))-(log((vp*h)/611))));
  Serial.println(dp);
  Serial.println(vp);
}

If dew point is dropping I will be moving to another function, if it is staying constant it will just repeat the test.

Thanks again.

void getDewPoint(double)

It's pointless to say that the function takes a double when you don't assign a name to the argument. That means that you can't reference the value in the function, so taking a double is pointless.

Why do you need to get the dew point more often than every 5 minutes? Even if you do, why not simply record the value every 5 minutes. The values every 5 minutes are either the same, increasing or decreasing.

Also, that's not the place for Serial.begin ().

Do your Serial.begin() call in setup().

you need something like this

//
//    FILE: dewPoint.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: demo (incomplete)
//    DATE: 204-11-23
//     URL:
//
// Released to the public domain
//

unsigned long lastTime = 0;
double lastDewPoint;
double dewPoint;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Start ");
  
  // ... other code 
  lastDewPoint = getDewPoint();
  // ...
}


void loop()
{
  if (millis() - lastTime > 5*60*1000UL)
  {
    lastTime = millis();
    dewPoint = getDewPoint();
    if (lastDewPoint > dewPoint) Serial.println("dewpoint dropping");  // call your function here
    else if (lastDewPoint < dewPoint) Serial.println("dewpoint rising");
    lastDewPoint = dewPoint;  
  }
  // do other stuff here
}


double getDewPoint()
{
  double h = 100; //htu.readHumidity();  // patched to make compiler happy :)
  double dt = 1000; //htu.readTemperature();
  double vp = 6.11 * pow(10, (7.5 * dt)/( 237.3 + dt) );
  double dp = 237.3 * log( vp * h / 611) / ( 7.5 * log(10) - log(vp * h / 611) );
  return dp;
}

Thanks a lot guys!

Paul-Im obviously very new and dont quite understand what goes inside the (). Ive searched around but cant seem to find much info, likely because I dont know the correct search terms. Can you point me somewhere that I could read to better understand?

Thanks a lot Rob! I really appreciate you doing that. To make sure I understand I should always put double/float/int before a variable even if it was declared in the beginning of the sketch. I realize you didn't see the beginning but I do have:

double h =0
double dt=0 etc...

I am sure that I wasn't exactly clear on what I am trying to accomplish. I would like to monitor the dewpoint over a 5 minute period to determine if the dewpoint is changing. This would be to ensure that there isn't a false decision made based on a snapshot reading.

Rob-
I found your Running Median class, Arduino Playground - RunningMedian.

It seems that this may be what I need. Do you agree or have a better/different solution?

Thanks.

timmyjane:
Thanks a lot Rob! I really appreciate you doing that. To make sure I understand I should always put double/float/int before a variable even if it was declared in the beginning of the sketch. I realize you didn't see the beginning but I do have:

double h =0
double dt=0 etc...

only the first time you need to tell the compiler what type it is. There after it knows. Furthermore there exists something called scope which indicates on what level the variable is known. You can have a global variable that is known everywhere, or a local variable with the same name that is only known inside a function or a compound block. Within a scope names must be unique. A scope is defined by a { } pair so an if statement or a for loop have their own scope;

here some code that shows effect of scope on different levels.

int a = 10;

void setup()
{
  Serial.begin(9600);
  Serial.println(a);

  int b = func(a); 

  for (int a = 0; a <3; a++)
  {
      Serial.println(a);
  }

  if (b > a)
  {
    int a = 3;
    Serial.println(a);
  }
  else 
  {
    int a = 4;
    Serial.println(a);
  }    
}


int func(int x)
{
  int a = 5;
  Serial.println(a);
  Serial.println(x);
  return a;
}

void loop(){}

Can you point me somewhere that I could read to better understand?

Forget the internet. Get a book.

That's good advice Paul and exactly what I have been doing the last few hours, referencing my library. Sometime it is difficult to find what you need on the net because you only get snippets of information.