Code for an Arduino Automatic Transfer Switch

the function delay() should have been named

freeze_microcontroller_totally_pause_all_code_exection_until_freezingtime_is_over()

The long and clearly speaking name would make users very hesistant to use it.

If you estimate: how many hours of learning is it worth to make your code execute more reliable?
If your answer is 20 hours or more.
Well it will take maybe 2 to 3 hours to learn the basics of non-blocking timing and another 5 to 10 hours to apply it your your code.

here is a tutorial to learn the basic principle of non-blocking timing

best regards Stefan