Need help data-logging final values to an SD card

It would help if you read the frist post in this thread and learned to properly post the code. The cost is unintellegible, doesn't complile, and there seems to be too much of it.

Since you have calculated speed, why don't you just

float speed;

loop.......
Serial.print (speed):

If that sounds like a good idea, you could go on using standard SD code to

        myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(speed);
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE