Recording servo moments and playing them back with push button

Hello,

How can I use a potentiometer and push button to play back my servo motor movements?
I have a code from the internet but it doesn't seem to work for me...

You need to post your code here so we can see it.

And please use the code button </>so your code looks like thisand is easy to copy to a text editor

...R

Code looks something like this and it isn't mine.

#include <Servo.h>
Servo Servo1;
int AnalogOut = 0;
int NewAnalogOut = 0;
int pin_Button = 8;
int pin_Button_State = 0;
int pin_Button_State_Last = 0;
int storage[800];
int storage_loc = 0;
int recording = 0;

void setup() {
   Serial.begin(9600);
   Servo1.attach(9);
   pinMode(pin_Button, INPUT);
}
void loop() {
  pin_Button_State = digitalRead(pin_Button);
  if (pin_Button_State != pin_Button_State_Last) {
      if (pin_Button_State == HIGH) {
        recording++;
        if (recording == 2) {
            storage[storage_loc] = 777;
        }
      }
     delay(50);
  }
   pin_Button_State_Last = pin_Button_State;

   if ( recording == 0) {
      int sensorValue = analogRead(A0);
      NewAnalogOut = map(sensorValue, 0, 1023, 0, 179);
      if (abs(NewAnalogOut - AnalogOut) > 2) {
        Servo1.write(AnalogOut);
        AnalogOut = NewAnalogOut;
      }
   }
     delay(1);
     if (recording == 1) {
       recording = 1;
       if (storage_loc < 800) {
         storage[storage_loc]=NewAnalogOut;
         delay(100);
         Serial.println(storage[storage_loc]);
         storage_loc++;
       }
     }else if (recording > 1) {
      while (1 == 1) {
         storage_loc = 0;
         if (storage_loc < 800 || storage[storage_loc] != 777) {
            Servo1.write(storage[storage_loc]);
            delay(100);
          }
        }
     }
}

Erks213:
Code looks something like this and it isn't mine.

I hope you really meant to say EXACTLY LIKE - because looking at "something" is not very constructive.

In any case, I am not impressed by the code.

You need to describe what you want to happen in as much detail as possible - never mind how it might be coded for the moment.

...R

I want to control servo movements with a potentiometer then use a push button to record servo movements(one push to start recording and at the same time control servo with pot.) and second push of the button to play all the servo movements back.
Have to do it for school, so I went for a easy way by using someone elses code, but it didn't work for me, so I'm here and willing to learn.

I think you need a lot more detail - for your own benefit mainly.

For instance, don't you need to record the time when the button is pressed as well as the angle of the potentiometer?

How many measurements do you want to record?

How long (minutes, hours, months) do you want to retain the saved data?

All these things and more impact on the design of the software.

...R
Planning and Implementing a Program