Zero crossing detection

Is Your zero crossing detection schematic working?
I got my dimmer working.
I'm using Arduino Mega 1280.
Here is my code, hope You understand:

Here is my circuit
I could send the complete program to compile.
I wanted to calculate the frequency of a signal and take samples in the same period when the frequency change in the middle of taking the samples have to cancel these samples ..

Thanks Gil