CapacitiveButton::CapacitiveButton(uint8_t sendPin, uint8_t receivePin){
	
	// Initialise variables
	capSense = CapacitiveSensor(sendPin, receivePin);	// Called with pins set to -1 as there is not default constructor
	_threshold = 1000;
	_number_of_samples = 30;
}
Пример #2
0
#include <CapacitiveSensor.h>

/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10M between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 */


CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);
    long total2 =  cs_4_6.capacitiveSensor(30);
    long total3 =  cs_4_8.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing
Пример #3
0
#include <user_config.h>
#include <SmingCore/SmingCore.h>

#include <Libraries/CapacitiveSensor/CapacitiveSensor.h>


// http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense
// Im using a 250K resistor currently. Using 500K seems to timeout. Im guessing that the higher
// Clock speed on the ESP means we need a higher charge current than arduino ??
// Further investigation required.



CapacitiveSensor   cs_0_2 = CapacitiveSensor(0,2); //Send pin 0, Receive Pin 2.


Timer procTimer;


void capsense()
{



    long total =  cs_0_2.capacitiveSensor(30); //Read sensor with 30 samples
    Serial.print("Sense Value: ");
    Serial.println(total); // print sensor output


}
const bool FDEBUG = false;						// unlocks full debug prints (readouts, precise values, etc)
const bool DEBUG = true;						// unlocks partial debug prints (state completion)
const bool haltUntilFirstTouch = true;			// halts lighting of LED sequence until first pads are touched

bool started = false;
bool fridgeUnlocked = false;
bool touchedNodes[8] = {false}; 				// these are only flipped to true when nodes are touched
bool stepsCompleted[5] = {false};
bool revertTo0 = false;							// needed to set LEd pair loop to 0 correctly
int previousCycle = -1;							// tracks previously touched pair
int cycleCount = 0;								// tracks loop count

int unlockedLed = 13;							// both onboard LED and external

CapacitiveSensor nodes[8] = {
								CapacitiveSensor(SIG_PIN,NODE1_PIN),
								CapacitiveSensor(SIG_PIN,NODE2_PIN),
								CapacitiveSensor(SIG_PIN,NODE3_PIN),
								CapacitiveSensor(SIG_PIN,NODE4_PIN),
								CapacitiveSensor(SIG_PIN,NODE5_PIN),
								CapacitiveSensor(SIG_PIN,NODE6_PIN),
								CapacitiveSensor(SIG_PIN,NODE7_PIN),
								CapacitiveSensor(SIG_PIN,NODE8_PIN)
							};

// Threshold to compare results with
long node_threshold = 170;	// it seems two simultaneously touched nodes may interfere. a lower threshold may help (120-175?)

void setup() {
	Serial.begin(9600);