Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

PassThroughPlusTone.ino 2.6KB

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