Rob - I may have explained badly what I need - what you kindly wrote is already in my code. I'm attaching it here so you can see:
// Controlling a servo position using a potentiometer (variable resistor)
// with the option of recording the movement, playing it in reverse and in original order.
// Adi Soffer 19.3.12
#include <Servo.h>
 Servo myservo;                    // create servo object to control a servo
 char buffer [5];                    //variable to hold keystrokes
 int potpin = 0;                     // analog pin used to connect the potentiometer
 int val;                           // variable to read the value from the analog pin
 const int valNumber = 500;         //variable to contain number of array members
 int incomingByte;                 //declare variable to hold incoming letter
 int servoPos[valNumber];          //create array of values for servo position
 const int waitForServo = 15;       //delay time to let servo get to position
 int recordModeLed = 3;               // defining pins for ui leds
 int homeModeLed = 4;
 int playModeLed = 5;
 int freeModeLed = 6;
 int freeSwitch = 7;                //defining pins for switches
 int recSwitch = 8;
 int homeSwitch = 9;
 int playSwitch = 10;
Â
 void setup()
{
  Serial.begin(9600);
  Serial.flush();
  myservo.attach(2);                         // attaches the servo on pin 2 to the servo object
  pinMode (freeModeLed, OUTPUT);            //defining LED pins as output
  pinMode (recordModeLed, OUTPUT);
  pinMode (homeModeLed, OUTPUT);
  pinMode (playModeLed, OUTPUT);
  pinMode (freeSwitch, INPUT);               //defining switch pins as input
  pinMode (recSwitch, INPUT);
  pinMode (homeSwitch, INPUT);
  pinMode (playSwitch, INPUT);
 Â
}
 void loop ()
{
Â
 digitalWrite (freeModeLed, LOW);
 digitalWrite (recordModeLed, LOW);
 digitalWrite (homeModeLed, LOW);
 digitalWrite (playModeLed, LOW);
Â
 if (Serial.available( ) > 0)
{
   incomingByte = Serial.read ( );
   if (incomingByte == 'f')
 {
     Serial.println ("Free mode");
     while (incomingByte == 'f')
  {
     digitalWrite (freeModeLed, HIGH);
     val = analogRead (potpin);
     val = map(val, 0, 1023, 0, 179);
     myservo.write (val);
     delay (waitForServo);
     if (Serial.available ( ) > 0)
   {
      incomingByte = Serial.read ( );
      if (incomingByte == 'r')
    {
      recordFunction ( ); Â
    }
     else if (incomingByte == 'h')
   {
     reverseFunction ( );
    }Â
     else if (incomingByte = 'p')
    {
      playBackFunction ( );
    } Â
   }Â
  }
 }Â
     else if (incomingByte == 'r')         // checks if input was r
    {          Â
     recordFunction ( );
    }
     else if (incomingByte == 'h')
   {
     reverseFunction ( );
    }
        else if (incomingByte = 'p')
    {
     playBackFunction ( );
     }
    }
   }
void playBackFunction ( )
   {
    digitalWrite (freeModeLed, LOW);
     digitalWrite (playModeLed, HIGH);
     Serial.println ("Playback Function");
      for (int i=0;i<(valNumber - 1);i++)
     {
      myservo.write (servoPos[i]);          //reads values from array in original order to servo
      delay (waitForServo);
      Serial.println (servoPos[i]);
     }
     digitalWrite (playModeLed, LOW);Â
   }
void reverseFunction ( )
   {
      digitalWrite (freeModeLed, LOW);
      digitalWrite (homeModeLed, HIGH);
      Serial.println ("Home function");
      for (int i=(valNumber - 1);i>0;i--)
     {
      myservo.write (servoPos[i]);         //reads values from array in reverse to servo
      delay(waitForServo);
      Serial.println (servoPos[i]);
     }
     digitalWrite (homeModeLed, LOW);
   }
 Â
void recordFunction ( )
{
     for (int c=6;c>3;c --)                  // three sec countdown to recording
     {
      digitalWrite (recordModeLed, HIGH);
      digitalWrite (c, HIGH);
      delay (700);
      digitalWrite (recordModeLed, LOW);
      digitalWrite (c, LOW);
      delay(300);
     }
     digitalWrite (recordModeLed, HIGH);
     Serial.println ("Record function");      // if so - prints record
     for (int i=0;i<(valNumber - 1) ;i++)        //for loop to store declared values of potÂ
    {
       val = analogRead(potpin);              // reads the value of the potentiometer (value between 0 and 1023)
       val = map(val, 0, 1023, 0, 179);              // scale it to use it with the servo (value between 0 and 180)
       myservo.write(val);                    // sets the servo position according to the scaled value
       servoPos [i]=val;                       // stores val in array "servoPos
       delay(waitForServo);                   // waits for the servo to get there
       Serial.println(val);                   // print values for checking
    }Â
    digitalWrite (recordModeLed, LOW);
}
In my code the "timing" of the recording function is predefined by the index number. What I'm trying to do is to be able to stop the recording when I decide externally - with a key stroke for example - and not just when the predefined 500 cycle ends. Than, if I stopped the cycle, I need the array to have an index number correct.
Did I manage to explain myself this time? I think most of you do this thing I'm trying to figure out off hand, which may explain why my question might seem redundant.