You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PassThroughPlusTone.ino 2.6KB

10 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include <Audio.h>
  2. #include <Bounce.h>
  3. #include <Wire.h>
  4. #include <SPI.h>
  5. #include <SD.h>
  6. const int myInput = AUDIO_INPUT_LINEIN;
  7. //const int myInput = AUDIO_INPUT_MIC;
  8. // Create the Audio components. These should be created in the
  9. // order data flows, inputs/sources -> processing -> outputs
  10. //
  11. //AudioInputAnalog analogPinInput(16); // analog A2 (pin 16)
  12. AudioInputI2S audioInput; // audio shield: mic or line-in
  13. AudioSynthWaveform toneLow(AudioWaveformSine);
  14. AudioSynthWaveform toneHigh(AudioWaveformTriangle);
  15. AudioMixer4 mixerLeft;
  16. AudioMixer4 mixerRight;
  17. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  18. AudioOutputPWM pwmOutput; // audio output with PWM on pins 3 & 4
  19. // Create Audio connections between the components
  20. //
  21. AudioConnection c1(audioInput, 0, mixerLeft, 0);
  22. AudioConnection c2(audioInput, 1, mixerRight, 0);
  23. AudioConnection c3(toneHigh, 0, mixerLeft, 1);
  24. AudioConnection c4(toneHigh, 0, mixerRight, 1);
  25. AudioConnection c5(toneLow, 0, mixerLeft, 2);
  26. AudioConnection c6(toneLow, 0, mixerRight, 2);
  27. AudioConnection c7(mixerLeft, 0, audioOutput, 0);
  28. AudioConnection c8(mixerRight, 0, audioOutput, 1);
  29. AudioConnection c9(mixerLeft, 0, pwmOutput, 0);
  30. // Create an object to control the audio shield.
  31. //
  32. AudioControlSGTL5000 audioShield;
  33. // Bounce objects to read two pushbuttons (pins 0 and 1)
  34. //
  35. Bounce button0 = Bounce(0, 12);
  36. Bounce button1 = Bounce(1, 12); // 12 ms debounce time
  37. void setup() {
  38. pinMode(0, INPUT_PULLUP);
  39. pinMode(1, INPUT_PULLUP);
  40. // Audio connections require memory to work. For more
  41. // detailed information, see the MemoryAndCpuUsage example
  42. AudioMemory(12);
  43. // Enable the audio shield and set the output volume.
  44. audioShield.enable();
  45. audioShield.inputSelect(myInput);
  46. audioShield.volume(0.60);
  47. }
  48. elapsedMillis volmsec=0;
  49. void loop() {
  50. // Check each button
  51. button0.update();
  52. button1.update();
  53. // fallingEdge = high (not pressed - voltage from pullup resistor)
  54. // to low (pressed - button connects pin to ground)
  55. if (button0.fallingEdge()) {
  56. toneLow.frequency(256);
  57. toneLow.amplitude(0.4);
  58. }
  59. if (button1.fallingEdge()) {
  60. toneHigh.frequency(980);
  61. toneHigh.amplitude(0.25);
  62. }
  63. // risingEdge = low (pressed - button connects pin to ground)
  64. // to high (not pressed - voltage from pullup resistor)
  65. if (button0.risingEdge()) {
  66. toneLow.amplitude(0);
  67. }
  68. if (button1.risingEdge()) {
  69. toneHigh.amplitude(0);
  70. }
  71. // every 50 ms, adjust the volume
  72. if (volmsec > 50) {
  73. float vol = analogRead(15);
  74. vol = vol / 10.24;
  75. audioShield.volume(vol);
  76. volmsec = 0;
  77. }
  78. }