| 61 | // Functions available in Wiring sketches, this library, and other libraries |
| 62 | |
| 63 | long CapacitiveSensor::capacitiveSensor(uint8_t samples) |
| 64 | { |
| 65 | total = 0; |
| 66 | if (samples == 0) return 0; |
| 67 | if (error < 0) return -1; // bad pin |
| 68 | |
| 69 | |
| 70 | for (uint8_t i = 0; i < samples; i++) { // loop for samples parameter - simple lowpass filter |
| 71 | if (SenseOneCycle() < 0) return -2; // variable over timeout |
| 72 | } |
| 73 | |
| 74 | // only calibrate if time is greater than CS_AutocaL_Millis and total is less than 10% of baseline |
| 75 | // this is an attempt to keep from calibrating when the sensor is seeing a "touched" signal |
| 76 | |
| 77 | if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) { |
| 78 | |
| 79 | // Serial.println(); // debugging |
| 80 | // Serial.println("auto-calibrate"); |
| 81 | // Serial.println(); |
| 82 | // delay(2000); */ |
| 83 | |
| 84 | leastTotal = 0x0FFFFFFFL; // reset for "autocalibrate" |
| 85 | lastCal = millis(); |
| 86 | } |
| 87 | /*else{ // debugging |
| 88 | Serial.print(" total = "); |
| 89 | Serial.print(total); |
| 90 | |
| 91 | Serial.print(" leastTotal = "); |
| 92 | Serial.println(leastTotal); |
| 93 | |
| 94 | Serial.print("total - leastTotal = "); |
| 95 | x = total - leastTotal ; |
| 96 | Serial.print(x); |
| 97 | Serial.print(" .1 * leastTotal = "); |
| 98 | x = (int)(.1 * (float)leastTotal); |
| 99 | Serial.println(x); |
| 100 | } */ |
| 101 | |
| 102 | // routine to subtract baseline (non-sensed capacitance) from sensor return |
| 103 | if (total < leastTotal) leastTotal = total; // set floor value to subtract from sensed value |
| 104 | return(total - leastTotal); |
| 105 | |
| 106 | } |
| 107 | |
| 108 | long CapacitiveSensor::capacitiveSensorRaw(uint8_t samples) |
| 109 | { |
nothing calls this directly
no outgoing calls
no test coverage detected