I always use the map function.
and never failed on me, This is the code that I use.
int oldVal;
int TOLERANCE= 5
int val = analogRead(pot);
val = map(val, 0, 1023, 0, 100);
int diff = abs(val - oldVal);
if (diff > TOLERANCE) )
{
Serial.print(val);
Serial.println("%");
oldVal = val;// only save if the val has changed enough to avoid slowly drifting
}
it helped me a lot when I need a certain value that isn't jumping around.
aideax:
int potentiometerValue = analogRead(potentiometerPin);
int percent = map(potentiometerValue , 0, 1023, 0, 100);
Serial.println(percent);Here's where I got the solution:
https://www.browncountylibrary.org/wp-content/uploads/2018/03/arduino_potentiometer.pdf