Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. #include <CapacitiveSensor.h>
  2.  
  3.  
  4.  
  5. #define speaker 11
  6.  
  7.  
  8. // Set the Send Pin & Receive Pin.
  9. CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3);
  10. CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
  11. CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);
  12. CapacitiveSensor cs_2_6 = CapacitiveSensor(2,6);
  13. CapacitiveSensor cs_2_7 = CapacitiveSensor(2,7);
  14. CapacitiveSensor cs_2_8 = CapacitiveSensor(2,8);
  15. CapacitiveSensor cs_2_9 = CapacitiveSensor(2,9);
  16. CapacitiveSensor cs_2_10 = CapacitiveSensor(2,10);
  17. CapacitiveSensor cs_2_12 = CapacitiveSensor(2,12);
  18. CapacitiveSensor cs_2_13 = CapacitiveSensor(2,13);
  19. CapacitiveSensor cs_2_22 = CapacitiveSensor(2,22);
  20. CapacitiveSensor cs_2_24 = CapacitiveSensor(2,24);
  21. CapacitiveSensor cs_2_26 = CapacitiveSensor(2,26);
  22.  
  23.  
  24. void setup()
  25. {
  26. cs_2_6.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
  27.  
  28. // Arduino start communicate with computer.
  29. Serial.begin(9600);
  30. }
  31.  
  32. void loop()
  33. {
  34. // Set a timer.
  35. long start = millis();
  36.  
  37. // Set the sensitivity of the sensors.
  38. long total1 = cs_2_3.capacitiveSensor(30);
  39. long total2 = cs_2_4.capacitiveSensor(30);
  40. long total3 = cs_2_5.capacitiveSensor(30);
  41. long total4 = cs_2_6.capacitiveSensor(30);
  42. long total5 = cs_2_7.capacitiveSensor(30);
  43. long total6 = cs_2_8.capacitiveSensor(30);
  44. long total7 = cs_2_9.capacitiveSensor(30);
  45. long total8 = cs_2_10.capacitiveSensor(30);
  46. long total9 = cs_2_12.capacitiveSensor(30);
  47. long total10 = cs_2_13.capacitiveSensor(30);
  48. long total11 = cs_2_22.capacitiveSensor(3000);
  49. long total12 = cs_2_24.capacitiveSensor(3000);
  50. long total13 = cs_2_26.capacitiveSensor(3000);
  51.  
  52.  
  53.  
  54.  
  55. Serial.print(millis() - start); // check on performance in milliseconds
  56. Serial.print("\t"); // tab character for debug windown spacing
  57.  
  58. Serial.print(total1); // print sensor output 1
  59. Serial.print("\t"); // Leave some space before print the next output
  60. Serial.print(total2); // print sensor output 2
  61. Serial.print("\t"); // Leave some space before print the next output
  62. Serial.print(total3); // print sensor output 3
  63. Serial.print("\t"); // Leave some space before print the next output
  64. Serial.print(total4); // print sensor output 4
  65. Serial.print("\t"); // Leave some space before print the next output
  66. Serial.print(total5); // print sensor output 5
  67. Serial.print("\t"); // Leave some space before print the next output
  68. Serial.print(total6); // print sensor output 6
  69. Serial.print("\t"); // Leave some space before print the next output
  70. Serial.print(total7); // print sensor output 7 // Leave some space before print the next output
  71. Serial.print("\t");
  72. Serial.println(total8); // print sensor output 8 // "println" - "ln" represent as "line", system will jump to next line after print the output.
  73. Serial.print("\t");
  74. Serial.println(total9);
  75. Serial.print("\t");
  76. Serial.println(total10);
  77. Serial.print("\t");
  78. Serial.println(total11);
  79. Serial.print("\t");
  80. Serial.println(total12);
  81. Serial.print("\t");
  82. Serial.println(total13);
  83.  
  84.  
  85.  
  86. // When hand is touched the sensor, the speaker will produce a tone.
  87. // I set a threshold for it, so that the sensor won't be too sensitive.
  88. if (total1 > 500) tone(speaker,226); // frequency
  89. if (total2 > 500) tone(speaker,277); // you can see https://www.arduino.cc/en/Tutorial/toneMelody if you want to change frequency
  90. if (total3 > 500) tone(speaker,294);
  91. if (total4 > 500) tone(speaker,311);
  92. if (total5 > 500) tone(speaker,330);
  93. if (total6 > 500) tone(speaker,349);
  94. if (total7 > 500) tone(speaker,370);
  95. if (total8 > 500) tone(speaker,392);
  96. if (total9 > 500) tone(speaker,415);
  97. if (total10 > 500) tone(speaker,440);
  98. if (total11 > 500) tone(speaker,466);
  99. if (total12 > 500) tone(speaker,494);
  100. if (total13 > 500) tone(speaker,523);
  101.  
  102. // When hand didn't touch on it, no tone is produced.
  103. if (total1<=500 & total2<=500 & total3<=500 & total4<=500 & total5<=500 & total6<=500 & total7<=500 & total8<=500 & total9<=500 & total10<=500 & total11<=500 & total12<=500 & total13<=500)
  104. noTone(speaker);
  105.  
  106. delay(10); // arbitrary delay to limit data to serial port
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement