Implementing this in a software routine on a TMR0 interrupt, the current data is read into the raw variable. If the average value minus the trip value is greater than the raw value, a sensor touch has occurred and the software responds accordingly. Otherwise, the sensor is determined to be untouched and the current value in TMR1 registers is averaged into the 16-point running average. The TMR1 registers are always cleared at the end of every TMR0 interrupt routine and the CPU returns to whatever it was doing prior to the interrupt, thus completing the basic system.