adjust servo from current position using a pot

Hi
Yes the calibration mode is entered using a dip switch on a digital input, this begins a while loop which loops through all the different setup areas, more while loops(around 12 servos each with upper and lower end points to set. All of which are entered by using another dip switch on another digital input. This is why I only included one end setting of one servo.

What I would like to happen is when the setup area for a particular servo end point is entered (LeftLowerTrim in the example) the servo should move to the previous location stored in the EEPROM (LeftLowerTrimValE in this example). From here you are able to move the servo using the pot. If you rotate the pot clockwise the servo will rotate servo clockwise in a linear fashion and likewise if the pot is rotated counter clockwise the servo would rotate counter clockwise. Once the new desired location is obtained press the accept button and the new value is stored in the EEPROM to be recalled once calibration mode is exited.

Yes I am aware about the EEPROM writes that is why I added the Accept button the new value will only be written to the EEPROM when this button is pressed (momentary pb)

If this is not enough detail please let me know.

P.S. I dug up a pot and ran the second lot of code posted, this does not work and the servo just jumps between LeftLowerTrimValE and LowerMap. LowerMap value also does not change. Thinking maybe I need a condition to only allow InitialTrimVal=TrimVal; //Setup something to compare values to to occur once when the while loop is first ran?

In this code I am trying to use LowerMap and UpperMap to map the values of the pot from the current position to the lower and upper extremities of the input (0 and 1023) to a range of 0 to current servo location and current servo location to 90 (0 to 90 is the end point range available). Then use an if statement to determine which way the pot has moved and adjust the servo location accordingly.

Any help, ideas, info would be greatly appreciated.

below is the full code I ran

#include <Servo.h>  //include servo libery
#include <EEPROM.h> //Allow to read and write to EEPROM 

Servo WingFoldLeft;

int Accept=2;  //pin 2
int AcceptVal=LOW;

int Trims=3;  //analog pin 3
int TrimVal=0;
int InitialTrimVal=0;

int LeftLowerTrim=4;  // pin4
int LeftLowerTrimV=LOW;
int LeftLowerTrimVal=0;
int LeftLowerTrimValE=0;

int LowerMap=0;
int UpperMap=0;

void setup(){

 WingFoldLeft.attach(5);  //pin5
pinMode(Accept, INPUT);
pinMode(LeftLowerTrim, INPUT);
pinMode(Trims,INPUT);
EEPROM.write(LeftLowerTrimValE,90);  //Use 90 as a starting point

  Serial.begin(9600);
  
}

void loop(){


//TrimVal=map(TrimVal,0,1023,0,1023);

LeftLowerTrimVal=EEPROM.read(LeftLowerTrimValE);
LeftLowerTrimV=digitalRead(LeftLowerTrim);
AcceptVal=digitalRead(Accept);
TrimVal=analogRead(Trims);
WingFoldLeft.write(LeftLowerTrimVal);
 
Serial.print("trim setup = ");  
Serial.println(LeftLowerTrimV);
Serial.print("Accept = ");
Serial.println(AcceptVal);
Serial.print("TrimVal = ");
Serial.println(TrimVal);
  
while(LeftLowerTrimV==HIGH){
Serial.print("trim setup = ");
Serial.println(LeftLowerTrimV);
Serial.print("Accept = ");
Serial.println(AcceptVal);
Serial.print("TrimVal = ");
Serial.println(TrimVal);
Serial.print("LowerMap = ");
Serial.println(LowerMap);
Serial.print("UpperMap = ");
Serial.println(UpperMap);

AcceptVal=digitalRead(Accept);    //Read the digital input 9 - Accept  
TrimVal=analogRead(Trims);  //Read the trim pot value
LeftLowerTrimVal=EEPROM.read(LeftLowerTrimValE);

WingFoldLeft.write(LeftLowerTrimVal);  //write servo to current lower trim value stored in EEPROM

//Only allow to happen once.
InitialTrimVal=TrimVal; //Setup something to compare values to

delay(500);  //Allow time for trim pot to be adjusted

LowerMap=map(TrimVal, 0,TrimVal, 0, LeftLowerTrimVal);   //Map from 0 to the current trim pot value and current servo location (Lower end)
UpperMap=map(TrimVal, 1023, TrimVal, 90, LeftLowerTrimVal); //Map from 90 to the curretn trim pot value and current servo location (Upper end)

//use the lower map if the initial trim value is larger then the current trim value (pot has been turnd down and input is less)
if (InitialTrimVal>LowerMap){
WingFoldLeft.write(LowerMap);
  if(AcceptVal==HIGH){                                 //Only change LeftLowerTrimVal if accept is pressed
    EEPROM.write(LeftLowerTrimValE, LowerMap); //Stores value in EEPROM so it can be recalled once calibration mode is exited                                  
  }
}

//use the upper map if the initial trim value is less then the current trim value (pot has been turnd up and input is more)
if (InitialTrimVal<LowerMap){
WingFoldLeft.write(UpperMap);
  if(AcceptVal==HIGH){                                 //Only change LeftLowerTrimVal if accept is pressed
    EEPROM.write(LeftLowerTrimValE, UpperMap); //Stores value in EEPROM so it can be recalled once calibration mode is exited                                  
  }
}

LeftLowerTrimV=digitalRead(LeftLowerTrim);                   //Check to see if setup selections conditions have changed
delay(200); //allow time for servo to move to new location
}

delay(500);  //for serial coms
}