A note to auto exit after say 500 ms:

Within the while loop put an If time>500 then exit1

So the user does not need to hold the button more than the necessary time.

Ioannis