Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

119 lines
3.7KB

  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SD.h>
  4. #include <Bounce.h>
  5. // WAV files converted to code by wav2sketch
  6. #include "AudioSampleSnare.h" // http://www.freesound.org/people/KEVOY/sounds/82583/
  7. #include "AudioSampleTomtom.h" // http://www.freesound.org/people/zgump/sounds/86334/
  8. #include "AudioSampleHihat.h" // http://www.freesound.org/people/mhc/sounds/102790/
  9. #include "AudioSampleKick.h" // http://www.freesound.org/people/DWSD/sounds/171104/
  10. #include "AudioSampleGong.h" // http://www.freesound.org/people/juskiddink/sounds/86773/
  11. #include "AudioSampleCashregister.h" // http://www.freesound.org/people/kiddpark/sounds/201159/
  12. // Create the Audio components. These should be created in the
  13. // order data flows, inputs/sources -> processing -> outputs
  14. //
  15. AudioPlayMemory sound0;
  16. AudioPlayMemory sound1; // six memory players, so we can play
  17. AudioPlayMemory sound2; // all six sounds simultaneously
  18. AudioPlayMemory sound3;
  19. AudioPlayMemory sound4;
  20. AudioPlayMemory sound5;
  21. AudioMixer4 mix1; // two 4-channel mixers are needed in
  22. AudioMixer4 mix2; // tandem to combine 6 audio sources
  23. AudioOutputI2S headphones;
  24. AudioOutputAnalog dac; // play to both I2S audio board and on-chip DAC
  25. // Create Audio connections between the components
  26. //
  27. AudioConnection c1(sound0, 0, mix1, 0);
  28. AudioConnection c2(sound1, 0, mix1, 1);
  29. AudioConnection c3(sound2, 0, mix1, 2);
  30. AudioConnection c4(sound3, 0, mix1, 3);
  31. AudioConnection c5(mix1, 0, mix2, 0); // output of mix1 into 1st input on mix2
  32. AudioConnection c6(sound4, 0, mix2, 1);
  33. AudioConnection c7(sound5, 0, mix2, 2);
  34. AudioConnection c8(mix2, 0, headphones, 0);
  35. AudioConnection c9(mix2, 0, headphones, 1);
  36. AudioConnection c10(mix2, 0, dac, 0);
  37. // Create an object to control the audio shield.
  38. //
  39. AudioControlSGTL5000 audioShield;
  40. // Bounce objects to read six pushbuttons (pins 0-5)
  41. //
  42. Bounce button0 = Bounce(0, 5);
  43. Bounce button1 = Bounce(1, 5); // 5 ms debounce time
  44. Bounce button2 = Bounce(2, 5);
  45. Bounce button3 = Bounce(3, 5);
  46. Bounce button4 = Bounce(4, 5);
  47. Bounce button5 = Bounce(5, 5);
  48. void setup() {
  49. // Configure the pushbutton pins for pullups.
  50. // Each button should connect from the pin to GND.
  51. pinMode(0, INPUT_PULLUP);
  52. pinMode(1, INPUT_PULLUP);
  53. pinMode(2, INPUT_PULLUP);
  54. pinMode(3, INPUT_PULLUP);
  55. pinMode(4, INPUT_PULLUP);
  56. pinMode(5, INPUT_PULLUP);
  57. // Audio connections require memory to work. For more
  58. // detailed information, see the MemoryAndCpuUsage example
  59. AudioMemory(10);
  60. // turn on the output
  61. audioShield.enable();
  62. audioShield.volume(50);
  63. // reduce the gain on mixer channels, so more than 1
  64. // sound can play simultaneously without clipping
  65. mix1.gain(0, 0.4);
  66. mix1.gain(1, 0.4);
  67. mix1.gain(2, 0.4);
  68. mix1.gain(3, 0.4);
  69. mix2.gain(1, 0.4);
  70. mix2.gain(2, 0.4);
  71. }
  72. void loop() {
  73. // Update all the button objects
  74. button0.update();
  75. button1.update();
  76. button2.update();
  77. button3.update();
  78. button4.update();
  79. button5.update();
  80. // When the buttons are pressed, just start a sound playing.
  81. // The audio library will play each sound through the mixers
  82. // so any combination can play simultaneously.
  83. //
  84. if (button0.fallingEdge()) {
  85. sound0.play(AudioSampleSnare);
  86. }
  87. if (button1.fallingEdge()) {
  88. sound1.play(AudioSampleTomtom);
  89. }
  90. if (button2.fallingEdge()) {
  91. sound2.play(AudioSampleHihat);
  92. }
  93. if (button3.fallingEdge()) {
  94. sound3.play(AudioSampleKick);
  95. }
  96. if (button4.fallingEdge()) {
  97. // comment this line to work with Teensy 3.0.
  98. // the Gong sound is very long, too much for 3.0's memory
  99. sound4.play(AudioSampleGong);
  100. }
  101. if (button5.fallingEdge()) {
  102. sound5.play(AudioSampleCashregister);
  103. }
  104. }