Pay attention, he says he wants to 1) use a capacitive button as a toggle switch and 2) debounce the input from CapSense.

@BlackSnake: Firstly, how have you implemented the hardware? Do you have a soft touch area or a rigid one? With capacitive sensing, you may not really need to do debouncing, but I'll share one way you can if you think you need to.

There are MANY ways to debounce an input, but in this case you should probably using a summing threshold. Create a variable that will be used as a counter. Now, increment this counter every time total1 goes over your threshold (just like you are lighting the LED). If total1 is less than the threshold, reset the counter.

Right after you've incremented the counter, check to see that the counter itself has reached a certain threshold. In other words, you can use a counter to make sure that the switch has been pressed for X amount of clock cycles (which in reality could be a very short period of time). As soon as the counter has reached a certain threshold, you know that you can then toggle a boolean variable that indicates the state of the switch.