Window opener opens window again and again due to Void loop

I believe @Robin2 meant for you to move the line:

int lastAnalogValue = 0;

To the top of program and delete it from where it was (line 21 now).