Using potentiometer joystick to simulate pushbutton switch

Throw away that debounce code for a digital input. You are better off with the StateChangeDetection example. Assume the analog "button" is pressed while analogRead() of the axis returns a value higher than some threshold. On every state change toggle a bool variable and activate the relay accordingly.