Although I don't know all about Arduino programming, I am a fairly decent programmer in C++/Java.
You may not need to use an array to store your previous values, if you are only comparing the 2 previous values.
In this case, in your loop() function, (or if you are using a separate function, just put this in the for/while loop or whatever)
First off, declare your variables to be global, so they can be used in any function. Do this by putting the variable name BEFORE any of the functions.
Example:
int oldValue;
int currentValue;
void setup()
{
oldValue = 0;
currentValue = 0;
//Set the values to be 0 when we first start
}
void loop()
{
oldValue = currentValue; //Every iteration the Arduino runs through, //assign oldValue to be what the previous currentValue is.
currentValue = getValueFromIR() //assign currentValue to the what //the function returns
/*
Okay, so I used getValueFromIR(), because I don't know how the exact function for the arduino to read a analog/digital value. That's up to you. It might be like digitalRead(pinNumber) or something?
*/
//do our logic tests
if( (oldValue > 20) && (currentValue <150))
{
blowUpWorld(); //Don't do that please. :(
}
} //End Loop();
What this will basically do, is each time the Arduino runs through the "loop" cycle, (which as I understand, is constantly, unless hung up in another "loop" in a separate function) it will update the variables for you to use.
You MAY wish to wait for the arduino to run through at least one loop cycle first, because in the first iteration, the oldValue will always be 0.
In order to wait for at least 1 iteration, simply add a counter variable, (unless the Arduino environment has something for that)
I hope that makes sense...
If someone who knows more about the Arduino environment chimes in about why this won't work, then oopsie-daisy.