CapacitiveSensor::CapacitiveSensor(uint8_t sendPin, uint8_t receivePin)
{
	// initialize this instance's variables
	// Serial.begin(9600);		// for debugging
	error = 1;
	loopTimingFactor = 310;		// determined empirically -  a hack

	CS_Timeout_Millis = (2000 * (float)loopTimingFactor * (float)F_CPU) / 16000000;
	CS_AutocaL_Millis = 20000;

	// Serial.print("timwOut =  ");
	// Serial.println(CS_Timeout_Millis);

	// get pin mapping and port for send Pin - from PinMode function in core

#ifdef NUM_DIGITAL_PINS
	if (sendPin >= NUM_DIGITAL_PINS) error = -1;
	if (receivePin >= NUM_DIGITAL_PINS) error = -1;
#endif

	pinMode(sendPin, OUTPUT);						// sendpin to OUTPUT
	pinMode(receivePin, INPUT);						// receivePin to INPUT
	digitalWrite(sendPin, LOW);

	sBit = PIN_TO_BITMASK(sendPin);					// get send pin's ports and bitmask
	sReg = PIN_TO_BASEREG(sendPin);					// get pointer to output register

	rBit = PIN_TO_BITMASK(receivePin);				// get receive pin's ports and bitmask
	rReg = PIN_TO_BASEREG(receivePin);

	// get pin mapping and port for receive Pin - from digital pin functions in Wiring.c
	leastTotal = 0x0FFFFFFFL;   // input large value for autocalibrate begin
	lastCal = millis();         // set millis for start
}
예제 #2
0
void initialize_button(uint8_t pin1, int8_t pin2)
{
//    pinMode(pin1, INPUT);
//    digitalWrite(pin1, HIGH); // enable pullup
    pinMode(pin1, INPUT_PULLUP);
    
    button1.pin = pin1;
    button1.reg = PIN_TO_INPUT_REG(pin1);
    button1.bitmask = PIN_TO_BITMASK(pin1);
    button_bit[0]   = PIN_TO_BITMASK(pin1);
    
    if (pin2 != -1) {
//        pinMode(pin2, INPUT);
//        digitalWrite(pin2, HIGH); // enable pullup
        pinMode(pin2, INPUT_PULLUP);

        button2.pin = pin2;
        button2.reg = PIN_TO_INPUT_REG(pin2);
        button2.bitmask = PIN_TO_BITMASK(pin2);
        button_bit[1]   = PIN_TO_BITMASK(pin2);
        
        button_count = 2;
    }
}