I'm reading the distance with Arduino ultrasonic kit. i want to show the longest distance during the session. i used shift register to have a previous value then I compared them with new the new one, but I think my algorithm is wrong.
Thanks for your help.
You should store the longest distance in the shift register, not the previous value. Basically in your code, it should be enough to connect "Select" function output to the input of the shift register, like this: