The Capacitive Sensor library provides support for capacitive sensing using buttons, sliders, and wheels. The library has only one instance but supports unlimited number of sensors.
Main features:
Implementation details The library uses simple algorithms to process the samples that are read from the sensor pads using Capacitive Sensor low-level library. The module acquires values from every enabled channel and then decides what to do, based on the algorithm. The following diagram shows the behavior of this library:
When the module senses that a slider or wheel was dragged, a new step must be calculated. Based on the algorithms, the module decides which of the pads were touched because one analog channel may be connected to two different pads. Then, it calculates the average from normalized values that were read on these pads and scales it to the abstract steps value that is provided by the user when creating the instance:
The auto-calibrating functionality means that the user does not need to provide minimum and maximum values that can be read on analog channels which are needed to normalize the read values, and can be hardware dependent.
You can create only one instance of this library. The number of pads in a single sensor is limited by the number of available analog input channels.
Using the same analog input for two different sensors is not recommended. This can cause an error when calculating the value due to different maximum and minimum values on them.
Using the same analog input channel on different pads within the same sensor is possible but has a limitation. The same two analog input channels cannot be set as neighboring pads more than once. See the figures below for details.
Correct design where analog inputs are never connected to neighboring pads more than once:
Wrong design where pads 1 and 2, as well as 4 and 5, are connected to AIN1 and AIN2:
The following is an example of initialization of two sensors. One of them is a slider, the other one is a button:
Consider the above initialization with added context_setting:
With the context of m_slider instance set to the slider_handler function, you can printf the step that is read on this slider in the event handler:
The maximum number of supported pads on a single slider or wheel is 32.
See the Capacitive Sensor Library Example for a full example that uses the Capacitive Sensor library.