How to control Servo from text file in SD Card ?

Hello everyone, I am using arduino to read the pulses from the encoder and output the pulses to the text file using the SD card module.
Now I want to use that text file to control Servo, how do I do? Or how to turn the list of numbers obtained in the txt file into an array also.
Thank you so much!
"Sorry for my bad english"

Please post an example of the text saved on the SD card and explain what you want the servo to do when the numbers are received. What is the relationship between the numbers and the servo positions ?

Do you know how to read the data from a file and print it on the Serial monitor ?

How many numbers need to be read into the array and what is the largest number ?

Thanks for answering!

I obtained the TEST file as follows,

https://drive.google.com/open?id=0BzLE4zTyZEyYaDlfZzJ2Vy1mQnc
https://drive.google.com/file/d/0BzLE4zTyZEyYaDlfZzJ2Vy1mQnc/view

Now I want arduino to read this test file in the order 0-> 1-2-> 3 ...-> 10-> 9-> 8-> 7-> 8 ... -> 20 so that when the arduino read to how much value, Servo will turn to the corner of many degrees. These numbers are Servo's angles.

Now I want arduino to read this test file

There is an example that comes with the SD library that reads a file.

It is up to YOU to modify that example, to store the data being read, and to recognize when the character read is an end of record marker, and to do something with the stored data when the character IS the end of record marker (if there is stored data).

Storing the character is easy.

char record[80];
byte index = 0;
   char c = someFile.read();
   if(c != '\r' && c != '\n') // Don't store the carriage return or line feed
   {
     if(index < 80) // Make sure that there is room to save the data
     {
        record[index++] = c;
        record[index] = '\0'; // Add a NULL at the end
     }
   }
   else
   {
      // Use the stored data

      // Reset for the next record
      index = 0;
      record[index] = '\0';
   }

Using the stored data is easy.

   int pos = atoi(record);
   someServo.write(pos);

What it appears that you are trying to do is replay a series of movements that the servo went through, BUT the servo initially moved through those positions at discreet times, with distinct intervals between the movements. You do not have that timing information, so you will not be able to replicate the initial movement.

Thank you, the information you give me is very few.

I use your suggestions to edit this code:

#include <SD.h>
#include <SPI.h>
#include <Servo.h>

Servo myservo;
File myFile;
int pinCS = 10;
char record[360];
byte index = 0;
//int pos ;
#define outputA 2
#define outputB 3

int counter = 0;
int aState;
int aLastState;

void setup() {
myservo.attach(9);
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);

Serial.begin (9600);
pinMode(pinCS, OUTPUT);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
}
void loop() {

aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
} else {
counter --;
}
Serial.print("Position: ");
Serial.println(counter);
myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:
if (myFile) {
Serial.println("Pulse out");
// Write to file
myFile.println(counter);
myFile.close(); // close the file
Serial.println("Done.");
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
}
char c = myFile.read();
if(c != '\r' && c != '\n') // Don't store the carriage return or line feed
{
if(index < 360) // Make sure that there is room to save the data
{
record[index++] = c;
record[index] = '\0'; // Add a NULL at the end
}
}
else
{
// Use the stored data

// Reset for the next record
index = 0;
record[index] = '\0';
}
int pos = atoi(record);
myservo.write(pos);
Serial.println(pos);

aLastState = aState;
}

But I do not understand why the value of the variable "pos" is always 0. I think the reason is because "pos" is variable and "record" is array. Can you help me?

Like you said, I would like to repeat the servo motions, but just the right angle and the time of movement is not important, I can regulate the speed of the servo when repeating. And I am very headache on this issue.

   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);

That looks pretty stupid. Do you plan to name the output pins inputFred and inputMary?

You are reading from a file you opened for write AND closed. Not a chance in hell of THAT working.

HAve you tried printing c when it is read from the file and record after adding the terminating '\0' ?

Thank you all for your comments.
I am very grateful for that
I think I have found a new solution with Analog Feedback Servo