I take it that the value you're adjusting is adjusted by relative movements of the potentiometer and not based on the absolute position.
Not sure what the difference is here? However the servo moves as the potentiometer is being rotated.
I found the problem. But first here is the current code I am using.
Everything else works just as I would like
#include <Servo.h> //include servo libery
#include <EEPROM.h> //Allow to read and write to EEPROM
boolean FirstTime;
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;
boolean FirstLowMap;
boolean FirstUpperMap;
void setup(){
WingFoldLeft.attach(5); //pin5
pinMode(Accept, INPUT);
pinMode(LeftLowerTrim, INPUT);
pinMode(Trims,INPUT);
EEPROM.write(LeftLowerTrimValE,45); //Use 90 as a starting point
Serial.begin(9600);
}
void loop(){
FirstTime=true; //Reset flag, put this inside calibrate while loop.
FirstLowMap=true;
FirstUpperMap=true;
LeftLowerTrimVal=EEPROM.read(LeftLowerTrimValE);
LeftLowerTrimV=digitalRead(LeftLowerTrim);
AcceptVal=digitalRead(Accept);
TrimVal=analogRead(Trims);
WingFoldLeft.write(LeftLowerTrimVal);
Serial.print("trim setup = ");
Serial.print(LeftLowerTrimV);
Serial.print("Accept = ");
Serial.print(AcceptVal);
Serial.print("TrimVal = ");
Serial.print(TrimVal);
Serial.print("first time = ");
Serial.println(FirstTime);
while(LeftLowerTrimV==HIGH){
Serial.print(" trim setup = ");
Serial.print(LeftLowerTrimV);
Serial.print(" Accept = ");
Serial.print(AcceptVal);
Serial.print(" TrimVal = ");
Serial.print(TrimVal);
Serial.print(" LowerMap = ");
Serial.print(LowerMap);
Serial.print(" UpperMap = ");
Serial.print(UpperMap);
Serial.print(" first time = ");
Serial.print(FirstTime);
Serial.print(" Initial trim = ");
Serial.println(InitialTrimVal);
AcceptVal=digitalRead(Accept); //Read the digital input 9 - Accept
TrimVal=analogRead(Trims); //Read the trim pot value
LeftLowerTrimVal=EEPROM.read(LeftLowerTrimValE);
//Only allow to happen once.
if(FirstTime==true){
InitialTrimVal=TrimVal; //Setup something to compare values to
WingFoldLeft.write(LeftLowerTrimVal); //write servo to current lower trim value stored in EEPROM
FirstTime=false;
}
//delay(500); //Allow time for trim pot to be adjusted
LowerMap=map(TrimVal, 0,InitialTrimVal, 0, LeftLowerTrimVal); //Map from 0 to the current trim pot value and current servo location (Lower end)
LowerMap=constrain(LowerMap, 0, 90);
UpperMap=map(TrimVal, InitialTrimVal, 1023, LeftLowerTrimVal, 90); //Map from 90 to the curretn trim pot value and current servo location (Upper end)
UpperMap=constrain(UpperMap, 0, 90);
//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>TrimVal){ //was >LowerMap
WingFoldLeft.write(LowerMap);
//need to only happen once
if(FirstLowMap==true){
if(AcceptVal==HIGH){
EEPROM.write(LeftLowerTrimValE, LowerMap);
FirstLowMap==false;
}
}
}
//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<TrimVal){ //was <LowerMap
WingFoldLeft.write(UpperMap);
//need to only happen once
if(FirstUpperMap==true){
if(AcceptVal==HIGH){
EEPROM.write(LeftLowerTrimValE, UpperMap);
FirstUpperMap==false;
}
}
}
LeftLowerTrimV=digitalRead(LeftLowerTrim); //Check to see if setup selections conditions have changed
delay(500); //allow time for servo to move to new location
}
delay(500); //for serial coms
}
The problem is in this area
//need to only happen once
if(FirstLowMap==true){
if(AcceptVal==HIGH){
EEPROM.write(LeftLowerTrimValE, LowerMap);
FirstLowMap==false;
}
}
as LeftLowerTrimVal is just a read of LeftLowerTrimValE and is in the maped value
LowerMap=map(TrimVal, 0,InitialTrimVal, 0, LeftLowerTrimVal); //Map from 0 to the current trim pot value and current servo location (Lower end)
LowerMap=constrain(LowerMap, 0, 90);
UpperMap=map(TrimVal, InitialTrimVal, 1023, LeftLowerTrimVal, 90); //Map from 90 to the curretn trim pot value and current servo location (Upper end)
UpperMap=constrain(UpperMap, 0, 90);
so once it is changed with EEPROM.write(LeftLowerTrimValE, LowerMap); it changes the maped value to either 0 or 90 and causes the servo to "jump" that is why I added the FirstLowMap boolean but it is still not fixing the problem. I thought this would only write the current value to the EEPROM and then when the code rolls around next time FirstLowMap would be false hence not allowing that code to write to th EEPROM again?