Incremental control of servo motor

Hello all!

I'm looking for way to control servo motor incrementaly. With that i mean, that if i want to move servo, then i specify just change of angle, instead absolute position.

In my particular case:
When loop starts frst time servo position needs to be, lets say 90 degrees. Then is required change for +30 degrees, so : 90+30= 110, and then position 110 degrees must be send to servo and stored. When loop repeats it takes 110 degrees for current angle, and if next required change is 50 degrees, then calc 110+50=160 and write pos= 160 deg.

I may try eeprom, but as far as i know, that type of memory is for more temporary data...
So, i would really appreceate every opinion!

best regards

so : 90+30= 110

What number base are you working in there?

Why EEPROM?
What's wrong with RAM, or does this system have to hold position across a reset?

Oh, i'm sorry, i meant 90+ 30=120 :cold_sweat:
No permanent storing is not needed.

Would you be kind and explain me how to write code to store and read from ram in my case? :smiley:

Thanks!

Would you be kind and explain me how to write code to store and read from ram in my case?

int oldPos = 30;
int incPos = 90;
int newPos = oldPos + incPos;

Ok, thats how change it. And it works!

Thanks

#include <Servo.h> 
Servo servo1;

int newPos;
int oldPos = 90;
int incPos;

void setup() 
{ 
  servo1.attach(9);
  Serial.begin(9600);
} 
 
void loop() 
{ 
incPos = Serial.read();
incPos++;
Serial.println(incPos);
newPos = oldPos + incPos;
servo1.write(newPos);
oldPos = newPos;
delay (100);
}