int encoderStep = 100; // Number of encoder pulses to trigger movement this will be base value
float allowedFluctuation = 0.4; // Maximum allowed fluctuation from base value +/- in percentage allowed value 0.0 - 1.0 (0% to 100%)
int totalEncoderSteps = 0; // New value for encoder steps to trigger the motor
const byte linearPot = A1;
void setup() {
Serial.begin(9600);
}
void loop() {
calculateNewEncoderSteps();
delay(100);
}
void calculateNewEncoderSteps() {
allowedFluctuation = constrain(allowedFluctuation, 0.0, 1.0); // Make sure the allowed fluctuation will be in 0.0-1.0 range
int potMap = map(analogRead(linearPot), 0, 1023, encoderStep - (encoderStep * allowedFluctuation), encoderStep + (encoderStep * allowedFluctuation)); // Map the potentiometer value from -100, 100 (Mid value will be 0)
Serial.print("Potentiometer Mapped value:");
Serial.println(potMap);
}