Advertisement
robynpan

Merlins Gautlet 0.0.01

May 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <CapacitiveSensor.h>
  2.  
  3. /*
  4.  * CapitiveSense Library Demo Sketch
  5.  * Paul Badger 2008
  6.  * Uses a high value resistor e.g. 10M between send pin and receive pin
  7.  * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
  8.  * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
  9.  */
  10.  
  11.  
  12. CapacitiveSensor   cs_4_2 = CapacitiveSensor(9,8);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
  13. CapacitiveSensor   cs_4_6 = CapacitiveSensor(9,7);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
  14. CapacitiveSensor   cs_4_8 = CapacitiveSensor(9,10);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
  15. long nonloop = 0;
  16.    
  17. void setup()                    
  18. {
  19.    Serial.begin(9600);
  20.  
  21. }
  22.  
  23. void loop()                    
  24. {
  25.     long start = millis();
  26.     long total1 =  cs_4_2.capacitiveSensor(3);
  27.     long total2 =  cs_4_6.capacitiveSensor(10);
  28.   long total3 =  cs_4_8.capacitiveSensor(3);
  29.  
  30.     //Serial.print(millis() - start);        // check on performance in milliseconds
  31.     //Serial.print("\t");                    // tab character for debug windown spacing
  32.  
  33.   if(total1>1000){  
  34.     if(nonloop!=1){    
  35.     Serial.print("A");  
  36.  //         Serial.print(total1);      // print sensor output 1
  37. Serial.print("\n");
  38.      delay(3);
  39.   // print sensor output 1
  40.   nonloop = 1;
  41.   }}
  42.  
  43.   if(total2>500){
  44.    
  45.     if(nonloop!=2){    
  46.     Serial.print("B");    
  47.   //    Serial.print(total2);      // print sensor output 1
  48. Serial.print("\n");
  49.     delay(3);
  50.   nonloop = 2;
  51.     }}
  52.     if(total3>1000){
  53.     if(nonloop!=3){  
  54.     Serial.print("C");  
  55. //    Serial.print(nonloop);
  56.  //        Serial.print(total3);      // print sensor output 1
  57. Serial.print("\n");
  58.      delay(3);
  59.   // print sensor output 1
  60.   nonloop = 3;
  61.   }}
  62.     //Serial.print("\t");
  63.             // print sensor output 2
  64.   //  Serial.print("\t");
  65.  //   Serial.println(total3);                // print sensor output 3
  66.  
  67.     delay(3);                            // arbitrary delay to limit data to serial port
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement