You have a few syntax and apparent missing logic issues… but since we haven’t a clue what you are tying to accomplish, how can we properly advise?
Best I can do is point out is that this… ligado2 = ! ligado2; probably should be this… ligado2 = !ligado2; (no space between the logical not and the variable) if what you are doing is inverting the variable.