so i found this code, which you can control servo with potentiometers, save the movement and play it. the only problem is that its only made for 1 servo and i need a code that i will controll multiple servos with mutiple potenciometers and save their position for robotic arm. Heres the code:
#include <Servo.h>
Servo servo1; // testing for a single potentiometer & servo combination
int AnalogOut = 0;
int NewAnalogOut = 0;
int pin_Button = 2; //attach button to PWM pin 13
int ledPin = 3; //status LED when push button is on
int pin_Button_State = 0;
int pin_Button_State_Last = 0;
int storage[200]; // # of positions for recording
int storage_loc = 0;
int recording = 0;
void setup() {
Serial.begin(9600); //turn on serial monitor
servo1.attach(7); //attach servo to PWM pin 7
pinMode(pin_Button, INPUT); //button for playback
pinMode(ledPin, OUTPUT); //LED is an output
}
void loop() {
if (recording == 0) { //not recording state
int sensorValue = analogRead(A0); //reading potentiometer at analog pin A0
NewAnalogOut = map(sensorValue, 0, 1023, 80, 0); //only has 80 degrees of rotation translated
if (abs(NewAnalogOut - AnalogOut) > 2) { //abs is for absolute, recording speed with value
AnalogOut = NewAnalogOut;
servo1.write(AnalogOut);
}
}
delay(1);
if ( recording == 1) { //recording turned on
digitalWrite(ledPin, HIGH); //turn on LED, to signify recording
recording = 1;
if (storage_loc < 200) {
int sensorValue = analogRead(A0);
NewAnalogOut = map(sensorValue, 0, 1023, 80, 0);
storage[storage_loc] = NewAnalogOut;
servo1.write(NewAnalogOut);
delay(100);
Serial.println(storage[storage_loc]);
storage_loc++;
}
} else if (recording > 1) { //recording playback, hit reset on arduino to stop playback
storage_loc = 0;
digitalWrite(ledPin, LOW);
while (1 == 1) {
if (storage_loc < 200 and storage[storage_loc] != 666) {
servo1.write(storage[storage_loc]);
storage_loc ++;
delay(100);
Serial.println(storage_loc);
Serial.println(storage[storage_loc]);
}
else{
storage_loc = 0;
}
}
}
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] = 666;
}
}
delay(50); //number of "frames" or speed it is recording at, due to number of delays in the loop
}
pin_Button_State_Last = pin_Button_State;
}
so i would appreciate it if somebody could tell me how to change the code to do that. thank you