Go Down

### Topic: Incremental control of servo motor (Read 1 time)previous topic - next topic

#### atorpred

##### Mar 26, 2014, 12:01 pmLast Edit: Mar 26, 2014, 12:03 pm by atorpred Reason: 1
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

#### AWOL

#1
##### Mar 26, 2014, 12:16 pm
Quote
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?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### atorpred

#2
##### Mar 26, 2014, 04:22 pm
Oh, i'm sorry, i meant 90+ 30=120
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?

Thanks!

#### PaulS

#3
##### Mar 26, 2014, 04:36 pm
Quote
Would you be kind and explain me how to write code to store and read from ram in my case?

Code: [Select]
`int oldPos = 30;int incPos = 90;int newPos = oldPos + incPos;`
`#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);} `