Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <CapacitiveSensor.h>
  2.  
  3. // Initialise all of our cap sensors. Each shares the
  4. // 12 pin.
  5.  
  6. CapacitiveSensor caps[] =
  7. {
  8. CapacitiveSensor(12,2),
  9. CapacitiveSensor(12,3),
  10. CapacitiveSensor(12,4),
  11. CapacitiveSensor(12,5),
  12. CapacitiveSensor(12,6),
  13. CapacitiveSensor(12,7)
  14. };
  15.  
  16. // Set a threshold value for which is used to
  17. // register a trigger event.
  18.  
  19. int threshold = 500;
  20.  
  21. // Set a long array to store the cap values.
  22.  
  23. long values[] =
  24. {
  25. 0,0,0,0,0,0
  26. };
  27.  
  28. // Set ref for an led that can be used to show
  29. // that the threshold has been exceeded.
  30.  
  31. int ledPin = 13;
  32.  
  33. void setup()
  34. {
  35. // Pause to allow for boot of an xbee or BT if connected
  36. // delay(6000);
  37.  
  38. for(int i=0; i < 6; i++)
  39. {
  40. // caps[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
  41. }
  42.  
  43. // Set the led pin as an output
  44.  
  45. pinMode(ledPin, OUTPUT);
  46.  
  47. // Set the led to off
  48.  
  49. digitalWrite(ledPin, LOW);
  50.  
  51. // Initialise the serial
  52.  
  53. Serial.begin(9600);
  54. }
  55.  
  56. void loop()
  57. {
  58. // Loop through the list of sensors and read the
  59. // value of each sensor.
  60. for(int i=0; i < 6; i++)
  61. {
  62. values[i] = caps[i].capacitiveSensor(30);
  63.  
  64. // Print the value of the sensor to serial
  65. Serial.print(values[i]);
  66.  
  67. // If we are at the final sensor in the list
  68. // do a print line, otherwise print a comma.
  69. if(i != 5) { Serial.print(","); }
  70. else { Serial.println(); }
  71. }
  72.  
  73. // Turn off the led
  74. digitalWrite(ledPin, LOW);
  75.  
  76. // Loop through the list of sensor values and if
  77. // one or more of the values is greater than the
  78. // threshold re-light the led
  79. for(int i=0; i < 6; i++)
  80. {
  81. if(values[i] > threshold)
  82. {
  83. digitalWrite(ledPin, HIGH);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement