I'm making a Record and Play Circuit with a servo and a potentiometer. I id it with one servo and one potentiometer (See the first picture and the first code). Now, I want to add a servo and a potentiometer to the circuit, but I want to keep only one button to record and play the movement of the micro servo.
For the second code, the one with two servo and two potentiometer, I want it to fit with the shematic (Second Picture, the one with two servo).
If somebody can help me, it would be nice !
Thank, and sorry for my english, I normaly speak french !
First Code :
#include <Servo.h>
Servo test;
int AnalogOut = 0;
int NewAnalogOut = 0;
int pin_Button = 12;
int pin_Button_State = 0;
int pin_Button_State_Last = 0;
int storage[250];
int storage_loc = 0;
int recording = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis;
int interval;
int storageTime[250];
void setup() {
Serial.begin(9600);
test.attach(11);
pinMode(pin_Button, INPUT);
}
void loop() {
if (recording == 0) {
int sensorValue = analogRead(A0);
NewAnalogOut = map(sensorValue, 0, 1023, 0, 180);
if (abs(NewAnalogOut - AnalogOut) > 2) {
test.write(AnalogOut);
AnalogOut = NewAnalogOut;
Serial.print("pos: ");
Serial.println(AnalogOut);
}
}
delay(10);
if ( recording == 1) {
if (storage_loc < 250) {
int sensorValue = analogRead(A0);
NewAnalogOut = map(sensorValue, 0, 1023, 0, 180);
if (abs(NewAnalogOut - AnalogOut) > 2) {
currentMillis = millis();
interval = currentMillis - previousMillis;
previousMillis = currentMillis;
test.write(AnalogOut);
AnalogOut = NewAnalogOut;
storage[storage_loc] = NewAnalogOut;
storageTime[storage_loc] = interval;
Serial.print("storage_loc: ");
Serial.print(storage_loc);
Serial.print(" --> pos: ");
Serial.print(storage[storage_loc]);
Serial.print(" --> interval: ");
Serial.println(interval);
storage_loc++;
}
}
delay(10);
} else if (recording > 1) {
storageTime[0] = 100; // sellega saab kõige esimese ajapunkti lühikeseks
storage[storage_loc] = 444; //sellega katkestab ära kui otsa saavad liigutused
storage_loc = 0;
delay(200);
while(true) {
if ((storage_loc < 250) && (storage[storage_loc] != 444)) {
test.write(storage[storage_loc]);
Serial.print("memory-storage_loc: ");
Serial.print(storage_loc);
Serial.print(" --> pos: ");
Serial.print(storage[storage_loc]);
Serial.print(" --> interval: ");
Serial.println(storageTime[storage_loc]);
delay(storageTime[storage_loc]);
storage_loc++; //enne seda polnud
}
else {
storage_loc = 0;
Serial.println(" --- repeat--- ");
delay(200);
}
}
}
pin_Button_State = digitalRead(pin_Button);
if (pin_Button_State != pin_Button_State_Last) {
if (pin_Button_State == HIGH) {
recording++;
Serial.println();
Serial.print(" Buttonpress: ");
Serial.println(recording);
}
else {
}
delay(50);
}
pin_Button_State_Last = pin_Button_State;
}
EDIT ------------------------------
Answer For VinceHerman:
"You have a sketch that works properly for one servo and pot, and you want to change it to make it work for 2 servos and 2 pots. Is that accurate?"
It's right !
Have tried to remake the code at specific place, but it didn't work.
I'M A BEGINNER IN PROGRAMING CODE