As the next step you should learn that auto-fornatting by pressing ctrl-t on the keyboard is a great help.
press the CTRL-key on your keyboard holdit down and press key "t" for a short moment.
Your opening and closing curly braces are scattered around without any care.
This makes your code hard to read.
It stays unclear which line of code belongs to which block
The reason why your values are "jumping" might be in the hardware.
So please post a NON-FRITZING but handdrawn schematic how yor potentiometer is wired to IO-pin A0
For smoothing out you have to add code that creates a moving average or you can use a library that is doing this
A more intuitive way for non-blocking timing is a function like used in this code
For analysing what is going on in your code you can use serial debug-output.
Anyway you should post an example with example numbers
what you exoect for values coming from the line of code
sensorValue = analogRead(A0);
and what do you expect as final result if everything works as you want it to
please use real numbers DON'T use words use example numbers!
int potPin = A0;
uint16_t sensorValue;
uint16_t presensorValue;
const int filter = 15;
uint16_t readinginterval = 100;
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}
unsigned long myReadTimer = 0; // Timer-variables MUST be of type unsigned long
void setup() {
Serial.begin(115200);
Serial.println( F("Setup-Start") );
pinMode(potPin, INPUT);
myReadTimer = millis(); // initialise timer
}
void loop() {
sensorValue = analogRead(A0);
if ( TimePeriodIsOver(myReadTimer,readinginterval) ) {
Serial.print("presensorValue - sensorValue=");
Serial.print(presensorValue - sensorValue);
Serial.print(" > ");
Serial.println(filter);
Serial.print(presensorValue);
Serial.print(" - ");
Serial.println (sensorValue);
if (abs(presensorValue - sensorValue) > filter) {
//update to the new value
presensorValue = sensorValue;
sensorValue = map(sensorValue, 0, 1023, -60, 0);
Serial.println(sensorValue);
}
}
}
and what do you expect as final result if everything works as you want it to
please use real numbers
I'm expecting it to print values between -60 to 6 but without printing repeated values.
so if the value is 10 the serial should not print:
10
10
10 etc
How long have you tinkered around with your code without getting the code to work?
How long did you post quick postings that did not lead to a solution?
There is advice from really experienced users you should take serious and follow the advice to speeding up finding a solution quicker as with hurrying and messing up