Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 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(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
  13.  
  14.  
  15. void setup()
  16. {
  17. cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
  18. Serial.begin(9600);
  19. Serial.print("HIGH: ");
  20. Serial.print(LOW);
  21. }
  22.  
  23. void sos() {
  24. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  25. delay(250); // wait for a second
  26. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  27. delay(250); // wait for a second
  28. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  29. delay(250); // wait for a second
  30. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  31. delay(250); // wait for a second
  32. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  33. delay(250); // wait for a second
  34. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  35. delay(250); // wait for a second
  36.  
  37. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  38. delay(500); // wait for a second
  39. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  40. delay(250); // wait for a second
  41. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  42. delay(500); // wait for a second
  43. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  44. delay(250); // wait for a second
  45. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  46. delay(500); // wait for a second
  47. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  48. delay(250); // wait for a second
  49.  
  50.  
  51. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  52. delay(250); // wait for a second
  53. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  54. delay(250); // wait for a second
  55. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  56. delay(250); // wait for a second
  57. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  58. delay(250); // wait for a second
  59. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  60. delay(250); // wait for a second
  61. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  62. delay(250); // wait for a second
  63.  
  64. delay(2000);
  65. }
  66.  
  67. void loop()
  68. {
  69. long start = millis();
  70. long total1 = cs_4_2.capacitiveSensor(30);
  71.  
  72. //Serial.print(millis() - start); // check on performance in milliseconds
  73. //Serial.print("\t"); // tab character for debug windown spacing
  74. if(total1 > 15000){
  75. sos();
  76.  
  77. }
  78. else {
  79.  
  80. digitalWrite(13, LOW);
  81. }
  82. //Serial.print(total1); // print sensor output 1
  83. //Serial.print("\t");
  84.  
  85. delay(10); // arbitrary delay to limit data to serial port
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement