previous value vs. current value of an analog read?

I'm looking to compare two values together, the values being the current value of an analog read and the previous value of an analog read.

I need two variables, one that represents the previous value and one for the current value. How can I define the variable for the previous value?

Well the if statement would be where the comparison would be done between two variables the prior and the latest: http://arduino.cc/en/Reference/If

Or did you want someone to write the sketch for you. :wink:

I edited my post to make a bit more sense:) I'm unsure as to how I can add a variable for the previous value in my analog read command.

You don't "add it" to the analog read command. Can you post your current sketch?

int currentValue;  // global variables are retained on each iteration of loop()
int previousValue;
int analogPin=0;

void setup() {
}

void loop() {
  previousValue = currentValue;  // store what was read last time
  currentValue = analogRead(analogPin);  // get a new reading
  if (previousValue != currentValue) {  // compare them
     // do something, they are different
  } else {
    // do something else, they are the same
  }
}[/code

[quote author=James C4S link=topic=64450.msg469729#msg469729 date=1308533145]

  if (previousValue != previousValue) {  // compare them

[/quote]

perhaps this.....

  if (currentValue != previousValue) {  // compare them

Amanda

commanda: [quote author=James C4S link=topic=64450.msg469729#msg469729 date=1308533145]

  if (previousValue != previousValue) {  // compare them

perhaps this.....

  if (currentValue != previousValue) {  // compare them

Amanda [/quote]

:D

A good example of why you should always include comments. ;)