Okay so I looked at the code and honestly, I don't see how to apply it with an analog reading.
Your line of code:-
if (analogValue < lowerthreshold) {
Turns that analogue reading into a digital one. Once that if is triggered it is just the same as if a button push were detected with a digitalRead.