Synchronization a button with a zerocrossing signal

I had to edit your post to correctly format your code for proper forum viewing, as documented in the Welcome Topic.