On/off switch with a light bulb

Hey,
I am trying to make a button that turns a light bulb on and off, and in the dash board i want to have a switch that i also can use and a fake light to show if it is on or not.
With the code i have written my switch in the iot works, but not the real one. and i cant get the light in the iot to turn on and off.
This is my code
projekt_jan16a.ino (6.3 KB)

The whole code i for frequency control, where i get an input signal and filter it and calculate the frequency from zero crossing. From the frequency i calculate the PWM.

PS. if you have any suggestions on how to improve my code please let me know

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination