PWM Driven Capacitive Sensing

This project from How to Make Almost Anything uses capacitive sensing values to drive PWM control for LED output. It uses the PWM function of the ATTiny45 to drive an LED for proximity sensing.

I established an "ambient" value-finding code sequence in the process. Then, every other value that came was subtracted from the ambient value, and that difference was set to the PWM limiter value, OCR0A. From serial tests, I noticed that the range of difference values was very small, and would only reach a top level of 150 or so. So setting OCR0A to this difference value was reasonable. Then, once the difference spiked past a certain point, I activated a flash method that would flash the PWM between MAX and MIN. This would also activate if there was sensed contact.

(P.S. As you may notice, there is a lot of residual flicker. Cap values (at least like this) are not really suitable for this kind of thing, as I learned. There needs to be something more stable.)