The library contains three main methods and some utility methods:
CapacitiveSensor CapacitiveSensor(byte sendPin, byte receivePin)
CapacitiveSensor creates an instance of the library.
Note: please note the capital letters, this is not the same method as below.
Example code for send/receive pins 3 & 4:
CapacitiveSensor [instanceName] = CapacitiveSensor(3,4);
long capacitiveSensorRaw(byte samples)
capacitiveSensorRaw requires one parameter, samples, and returns a long integer containing the absolute capacitance, in arbitrary units. The samples parameter can be used to increase the returned resolution, at the expense of slower performance. The returned value is not averaged over the number of samples, and the total value is reported.
capacitiveSensorRaw will return -2 if the capacitance value exceeds the value of CS_Timeout_Millis (in milliseconds). The default value for CS_Timeout_Millis 2000 milliseconds (2 seconds).
long capacitiveSensor(byte samples)
capacitiveSensor requires one parameter, samples, and returns a long containing the added (sensed) capacitance, in arbitrary units. capacitiveSensor keeps track of the lowest baseline (unsensed) capacitance, and subtracts that from the sensed capacitance, so it should report a low value in the unsensed condition.
eg:
long [varName][instanceName].capacitiveSensor([numSamples]);
set_CS_AutocaL_Millis( unsigned long autoCal_millis ):
This method changes the value of the CS_Autocal_Millis variable. This variable sets the interval between baseline capacitance re-calibrations. The default value is 20000 milliseconds (20 seconds).
This re-calibration may be turned off by using this method to set the CS_Autocal_Millis variable to a high value.
set_CS_Timeout_Millis( unsigned long timeout_millis ):
This method changes the value of the CS_Timeout_Millis variable. The default value is 2000 ms (2 seconds). "A timeout is necessary because the while loop, that does the timing in the CapacitiveSensor method, will lock-up the sketch (the function will never return) if, for example, the resistor between sendPin and receivePin becomes disconnected. "
eg:
void [instanceName].set_CS_Timeout_Millis(unsigned long timeout_millis);
reset_CS_AutoCal( unsigned long autoCal_millis ):
This method may be used to force an immediate re-calibration.
eg.
xxx void [instanceName].set_CS_AutocaL_Millis(unsigned long autoCal_millis);