#include <Servo.h>

// define servo and potentiometer pins
Servo myservo;
int potPin = A0;

// define variables
int potValue = 0;
int recordedValues[100];
int currentIndex = 0;

void setup() {
// attach servo to pin 3
myservo.attach(3);
myservo.write(0) ;
}

void loop() {
// read potentiometer value and store in variable
potValue = analogRead(potPin);
potValue = map(potValue,0,1023,0,180);
// set servo position to potentiometer value
myservo.write(potValue);

// record potentiometer value
recordedValues[currentIndex] = potValue;
currentIndex++;

// delay for stability
delay(100);

// play recorded values on servo
for (int i = 0; i < currentIndex; i++) {
myservo.write(recordedValues[i]);
delay(100);
}
}