Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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_5 = CapacitiveSensor(4,5); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
- int br = 0;
- int threshold = 100;
- bool reach100 = false;
- long total1;
- void setup()
- {
- cs_4_5.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
- pinMode(7, OUTPUT);
- pinMode(8,OUTPUT);
- if(total1 > threshold){
- reach100 = true;
- }else{
- reach100 = false;
- }
- Serial.begin(9600);
- }
- void loop()
- {
- long start = millis();
- total1 = cs_4_5.capacitiveSensor(30);
- //Serial.print(millis() - start); // check on performance in milliseconds
- //Serial.print("\t"); // tab character for debug windown spacing
- //Serial.print(total1); // print sensor output 1
- if(reach100 == true){
- digitalWrite(7,HIGH);
- digitalWrite(8,HIGH);
- }
- else
- {
- digitalWrite(7, LOW);
- digitalWrite(8,LOW);
- }
- if(!reach100 && total1 > threshold)
- {
- reach100 = true;
- br++;
- Serial.println("Counter: " + String(br));
- }
- if(total1 < threshold) reach100 = false;
- delay(10); // arbitrary delay to limit data to serial port
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement