I see. Thank you. I was just thinking, can I use MOSFETs to PWM it? Or can I convert it to DC then MOSFET it? Thanks.
Maybe you should define your needs and then find a solution?
SCR's & Triacs behave differently. Triacs are bidirectional! (so we can have higher resolution and less flicker)
We know the frequency of the AC being about 50/60Hhz depending where you are.
So we know the time between 1/2 cycles
We also know that if we apply a tiny gate voltage pulse the device starts to conduct, and will continue until the voltage across it's main terminals is zero. (zero crossing point - Mains is AC and the voltage will pass through a minimal voltage during each half cycle)
Thus by adjusting the time of the pulse relative to 0V crossing (after 0V occurred) we can vary how much of the (half) cycle that the Triac conducts. The further from the zero crossing detection, the shorter the conduction time (to the next zero crossing), so the less average voltage appears across our lamp.
Isolation from the mains is important so we are talking transformers, or optically isolated devices, hence opto zero-voltage detectors and opto-isolated diacs (diac NOT triac)
So, basically your code will be
read zero crossing device
delay for Tbrightnes (in uS to give you lots of resolution)
output high to diac
delay for XuSeconds (see data sheets)
output low to diac