Quick n easy touch sensing

Ive recently gotten into Arduino (uno)
After having done some Freescale and TI micros,
i just love the Ard IDE, simple and easy, and
it comes in native linux.
I just love debugging w/ the serial monitor.
The old break point / watch point stuff is a thing of the past.
(Real FW weenies roll their eyes at me!
I m a HW engineer.)

Ive done touch sensing on the Freescale micros before and
thought I d try it on the uno. It works really well.
All that you need is a 1meg pull up on your desired pin(s).
No need for a dedicated drive pin as it is uni polar.

It works by holding the pin low until it needs to be read.
Then, the pin is switched to input to allow it to charge.
The charging time is counted until
the pin crosses the logic threshold (6-20uS)
The more capacitance on the pin,
the longer it takes to charge.
Then, the pin is switched to output to discharge it.
Repeat the process as needed. I do mine @ ~60hz.

I like to use insulated magnet wire, so as
to not make a direct touch connection to the micro.
It might be advisable to put 10k in series with the pin
to help tolerate ESD.
Use two wires close enough to touch both of them.
One is grounded and the other goes to your pin.

You might need to #include <TimerOne.h> (not sure), as
timer1 (TCNT1) is needed to make this work.
It chugs at 16MHz / 62.5nS
All counts are based on this.
Declare all of your variables as int.

In void setup()
{ // pin 2 is used here as an example
pinMode( 2, OUTPUT); // set your pin low, internal no pull up
digitalWrite( 2, 0); // set it to output

In either void loop() or a timer interrupt put:

pinMode( 2, INPUT); // set pad to input to allow charge

padnew = TCNT1; // get starting count, @ 16MHz!, 63nS

while( !digitalRead( padpin) && TCNT1 < 0x0200); // wait for the pad to go hi, time out if too long (30uS)

padnew = TCNT1 - padnew; // get / normalize the reading

pinMode( padpin, OUTPUT); // set pad to output to discharge

padlpf += padnew - padlpf >> 2; // get new count and low pass filter / de bounce

padlpf has a number from ~100 (un touched) to ~200 (touched)
Qualify on that as press / release.