Added state variable at a higher level so it can be used several times throughout the section.
Also added if statements to check the status before switching, this is to prevent the light flicking off and fading up again if the light is already on. or vice versa if the light is already off, prevents it from going back to value 255 and fading down again.
I like bug fixes :-)