Advertisement
marquessamackenzie

Capacitive Sensor with Audio Output

Dec 11th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1.  
  2.  
  3. /*******
  4. * Marquessa MacKenzie
  5. * December 11/2020
  6. * Atelier 1: Discovery
  7. *
  8. * Original Code:
  9. Code for the Textile Game Controller Jam by Social Body Lab, Dames Making Game, & Game Play Lab.
  10. May 30, 2020 - June 6, 2020.
  11. This is code follows along the "How to Make an Capacitive Sensor Using E-Textile Materials" here: https://youtu.be/kTfoMyjtgws
  12. The code contains 1 capacitive sensor which lights up when touched.
  13. Circuit Playground Library:
  14. https://learn.adafruit.com/circuit-playground-lesson-number-0
  15. *
  16. *Added speaker putput from here: https://learn.adafruit.com/circuit-playground-music/using-the-circuit-playground-speaker
  17. *********/
  18.  
  19. /**Must include the Adafruit_CircuitPlayground.h**/
  20. #include <Adafruit_CircuitPlayground.h>
  21.  
  22. #define CAP_THRESHOLD 800 //increase this number if unintentional keypresses occur and
  23.  
  24. /**Setting up the ability to read capactive touch on the Circuit Playgroun**/
  25. /**If using capactive touch, you must include this line in your code!**/
  26. boolean capButton(uint8_t pad) {
  27. if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33.  
  34. void setup() {
  35. Serial.println(CircuitPlayground.readCap(6));
  36. Serial.begin(9600); // Starting the serial monitor
  37. CircuitPlayground.begin(); // Initiating the Circuit Playground
  38. }
  39.  
  40. void loop() {
  41. Serial.println(CircuitPlayground.readCap(6));
  42.  
  43. if (capButton(6)) {
  44. CircuitPlayground.playTone(1760,100); // output a 1760 Hz sound for a tenth of a second
  45. }
  46.  
  47. if (capButton(1)) {
  48. CircuitPlayground.playTone(440,100); // output a 440 Hz sound for a tenth of a second
  49. }
  50.  
  51. if (capButton(0)) {
  52. CircuitPlayground.playTone(800,100); // output a 800 Hz sound for a tenth of a second
  53. }
  54.  
  55.  
  56. // if (capButton(0)) { // if the 0 pin is activated through capactive touch
  57. // Serial.println("Pin 6 is activated!");
  58.  
  59. // for (int i = 0 ; i < 10; i++) { // loop through all of the lights and turn them on
  60. // CircuitPlayground.setPixelColor(i, 255, 0, 200); // pink colour
  61. // }
  62.  
  63. // } else { // turn off all of the LEDs
  64. // CircuitPlayground.clearPixels();
  65. // }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement