Find a Knob's Speed and Direction... Math!

I'm want to find out he speed and direction a person is turning a simple knob / potentiometer. My knob have the read value from 0 - 1025... So with the user spins the knob, I need to detect the rate at which he is spinning and also the direction... Is there a builtin math function I could use?

Example code would be amazing!!!
thanks for the help!
dan.

The pot will only return values 0-1023.

Speed is the rate of change of something over time. So you need to measure 2 things - the change in voltage measured thru the pot (the only measurement you talk about) and the time between readings.

Look at the blink without delay example to give you a way to working out how to do timing of things without using delay. For each time interval you measure the analog reading and then work out something meaningful for speed.

This gives you absolute and relative readings. Its using my statemachine library as a timer/sheduler.
The library is here: Arduino Playground - SMlib

#include <SM.h>
#include <stdlib.h>

SM Knob(Kread, Kwait);//statemachine used as scheduler
const int Kpin = 2;
int Kabs;//Absolute value
int Krel;//Relative value

void setup(){
  Serial.begin(115200);
}//setup()

void loop(){
  EXEC(Knob);//run sheduler
}//loop()

State Kread(){//once every 10ms
  Krel = analogRead(Kpin)-Kabs;//get relative reading
  Kabs += Krel;//recalculate absolute
  if(abs(Krel)>2) printout();//if change, print
}//Kread()

State Kwait(){
  if(Knob.Timeout(10)) Knob.Set(Kread, Kwait);//repeat every 10ms
}//Wait()

void printout(){
  Serial.print("Absolute: ");
  Serial.print(Kabs);
  Serial.print("\tRelative: ");
  //calculate rotation speed for 1023 points, 300degrees, 100 times/s
  Serial.print(Krel*29.3255131965);
  Serial.println("degrees/sec");
}//printout()