This seems to be a common project nowadays
Just search zero_cross
and you’ll find some more elaborate threads.
Another keyword in connection is SparkIntervalTimer
e.g. Alternative to Delay() within Interrupts?
But the short story - don’t use delays beyond a few microsec in an ISR!
A sidenote: digitalWriteFast()
is way faster (but with less sanity checking) than digitalWrite()
so it’s the way to do it inside an ISR.