I have written a sketch for my mobile platform, to determine total distance travelled. I'll save you the detail on how this is all setup...my main concern is the program/sketch. I have three questions:

1. Since I have to have very accurate data for this calculation to work, I have lots of "float"ing data. Any suggestions on a better way?

2. The final function (running total), is returning gibberish...any idea whats wrong?

3. How does this smoothing function (array) look?, any alternative (better) methods?

Thanks in advance! I'm still learning the Arduino, but enjoying every second.

`const int analogpinP1 = 1; // Analog input at pin 1 is "P1", StartPoint`

const int analogpinP2 = 2; // Analog input at pin 2 is "P2", FinishPoint

float StartPoint; //start point

float FinishPoint; //finish point

float factor; //calculation (estimation) factor

float speed; //estimated speed

float time; //current time since program started running

float elapsedtime; //elapsed time between iteration

float CurrentDistance; //distance traveled during this iteration

float TotalDistance; //total distance traveled since program started

//all of the following variables are used for smoothing analog input data

int sptotal;

int sparray[16];

int fptotal;

int fparray[16];

int i;

int count = 0;

void setup()

{

Serial.begin(9600); // initialize serial communications at 9600 bps:

}

void loop()

{

StartPoint = analogRead(analogpinP1);

sparray[count] = StartPoint;

count ++;

if (count == 16){

count=0;}

sptotal = 0;

for (i=0; i <=15; i ++){

sptotal = sptotal + sparray[i];}

StartPoint = (sptotal/16);

FinishPoint = analogRead(analogpinP2);

fparray[count] = FinishPoint;

count ++;

if (count == 16){

count=0;}

fptotal = 0;

for (i=0; i <=15; i ++){

fptotal = fptotal + fparray[i];}

FinishPoint = (fptotal/16);

float factor = ((StartPoint+(FinishPoint/3.248+101.486)))/250*1000000; //need to divide by 1000000, did this to maintain accuracy and not drop off digits

float speed =((2.57814*pow((StartPoint/3),.5))*pow(((2*(StartPoint/8.24))/((factor/1000000)*(1-pow((FinishPoint),3)))),2)); // calculate estimated total

elapsedtime = micros() - time; // how long since the last time something was stored in time

time = micros()/1000000; // store the new value;

CurrentDistance = speed * (elapsedtime/1000000)/3600; //distance traveled this iteration

TotalDistance = TotalDistance + CurrentDistance; //running total of distance

}