Firstly the speed of the code is completely limited by the Serial.write call - even at
115200 baud that's 87us per byte, almost as slow as the default analogRead() call.
So you have to poll the analog reading without doing Serial output, detect an event,
and only then report back.
To detect you need more circuitry.
Add a resistor from the wiper to a resistor to a digital output pin.
code like this:
int detect_loop ()
int l, h ;
digitalWrite (wiperbias_pin, LOW) ;
l = fastAnalogRead (A0) ;
digitalWrite (wiperbias_pin, HIGH) ;
h = fastAnalogRead (A0) ;
} while (h - l > THRESHOLD) ;
return (h + l) / 2 ;
Choose a resistance value that doesn't affect the readings very much when the soft
pot is being pressed, but has significant effect when not pressed - select a THRESHOLD
value that discriminates these two cases reliably. Bingo!