When averaging, you still have variations, only moved by a decimal place and/or slower.
What resolution do you need.
If you need less than 10-bit, you could add hysteresis.
Try this (untested) 8-bit output sketch.
Leo..
// converts the position of a 10k lin(B) pot to a byte (0-255)
// pot connected to A0, 5volt and ground
int rawValue; // raw reading
int oldValue; // for deadband
byte Byte; // final byte
byte oldByte; // for printing
void setup() {
Serial.begin(9600);
}
void loop() {
// rawValue = analogRead(A0); // dummy read, if needed
rawValue = analogRead(A0); // read pot
if (rawValue < (oldValue - 2) || rawValue > (oldValue + 2)) { // add some deadband
oldValue = rawValue; // update value
Byte = oldValue >> 2; // convert 10-bit to 8-bit
if (oldByte != Byte) { // only print if value changes
Serial.print("Byte is: ");
Serial.println(Byte);
oldByte = Byte; // update value
}
}
}
Edit:
I also wrote a 0-100% (101 values) version.