AC Dimmer time control

You have two separate sketches. Do they both work separately?

In your dimmer sketch, what happens if dimtime2 is greater than dimtime1?

      delayMicroseconds( dimtime1 - dimtime2);