MCPcopy Create free account
hub / github.com/PaulStoffregen/CapacitiveSensor / CapacitiveSensor

Method CapacitiveSensor

CapacitiveSensor.cpp:25–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23// Function that handles the creation and setup of instances
24
25CapacitiveSensor::CapacitiveSensor(uint8_t sendPin, uint8_t receivePin)
26{
27 // initialize this instance's variables
28 // Serial.begin(9600); // for debugging
29 error = 1;
30 loopTimingFactor = 310; // determined empirically - a hack
31
32 CS_Timeout_Millis = (2000 * (float)loopTimingFactor * (float)F_CPU) / 16000000;
33 CS_AutocaL_Millis = 20000;
34
35 // Serial.print("timwOut = ");
36 // Serial.println(CS_Timeout_Millis);
37
38 // get pin mapping and port for send Pin - from PinMode function in core
39
40#ifdef NUM_DIGITAL_PINS
41 if (sendPin >= NUM_DIGITAL_PINS) error = -1;
42 if (receivePin >= NUM_DIGITAL_PINS) error = -1;
43#endif
44
45 pinMode(sendPin, OUTPUT); // sendpin to OUTPUT
46 pinMode(receivePin, INPUT); // receivePin to INPUT
47 digitalWrite(sendPin, LOW);
48
49 sBit = PIN_TO_BITMASK(sendPin); // get send pin's ports and bitmask
50 sReg = PIN_TO_BASEREG(sendPin); // get pointer to output register
51
52 rBit = PIN_TO_BITMASK(receivePin); // get receive pin's ports and bitmask
53 rReg = PIN_TO_BASEREG(receivePin);
54
55 // get pin mapping and port for receive Pin - from digital pin functions in Wiring.c
56 leastTotal = 0x0FFFFFFFL; // input large value for autocalibrate begin
57 lastCal = millis(); // set millis for start
58}
59
60// Public Methods //////////////////////////////////////////////////////////////
61// Functions available in Wiring sketches, this library, and other libraries

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected