#include <Servo.h>
Servo Servo1;
int AnalogOut = 0;
int NewAnalogOut = 0;
int pin_Button = 9;
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(10);
pinMode(pin_Button, INPUT);
// put your setup code here, to run once:
}
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;
// put your main code here, to run repeatedly:
}
}
delay(50);
}
pin_Button_State_Last = pin_Button_State;
if (recording == 0) {
int sensorValue = analogRead(A0);
NewAnalogOut = map(sensorValue, 0, 1023, 0, 180);
if (abs(NewAnalogOut - AnalogOut) > 2) {
Servo1.write(AnalogOut);
AnalogOut = NewAnalogOut;
}
}
delay(1);
if ( recording == 1) {
recording = 1;
if (storage_loc < 1000) {
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);
}
}
}
}
After uploading there's also red text at the button which says: low memory available, stability problems may occur.
I can control the servo with the potentiometer just fine till i press the button then the servo just freezes no matter how much i turn the potentiometer.
Not a good idea to run servo power from the Arduino as the video shows or indeed even via a breadboard.
Give the servo some decent power, say 4 separate AA cells and run a common line from the aa negative back to the Arduino negative.
Signal to the Arduino pin 11 is ok.
Hi,
Can you post a link to data/specs of the servo?
Can you please post a schematic of your project?
Please do not use Fritzy, a hand drawn image will be fine.
Include ALL power supplies, component names and pin labels.
Not sure exactly what you mean here as the video shows first press to "record" whatever servo movement, any successive press, reads back the recorded movement from memory.
Do you have everything setup exactly the same as the video...??
There is also a later video showing more advanced code but also, the use of a separate supply for the servo, admittedly a larger servo but.........
also this line needs to change to 800.
if ( recording == 1) {
recording = 1;
if (storage_loc < 1000) {