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.

54 lines
1.4KB

  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SD.h>
  4. const int myInput = AUDIO_INPUT_LINEIN;
  5. //const int myInput = AUDIO_INPUT_MIC;
  6. // each filter requires a set up parameters
  7. int myFilterParameters[] = { // lowpass, Fc=800 Hz, Q=0.707
  8. 3224322, 6448644, 3224322, 1974735214, -913890679, 0, 0, 0};
  9. // Create the Audio components. These should be created in the
  10. // order data flows, inputs/sources -> processing -> outputs
  11. //
  12. AudioInputI2S audioInput; // audio shield: mic or line-in
  13. AudioFilterBiquad myFilter(myFilterParameters);
  14. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  15. // Create Audio connections between the components
  16. //
  17. AudioConnection c1(audioInput, 0, audioOutput, 0);
  18. AudioConnection c2(audioInput, 0, myFilter, 0);
  19. AudioConnection c3(myFilter, 0, audioOutput, 1);
  20. // Create an object to control the audio shield.
  21. //
  22. AudioControlSGTL5000 audioShield;
  23. void setup() {
  24. // Audio connections require memory to work. For more
  25. // detailed information, see the MemoryAndCpuUsage example
  26. AudioMemory(12);
  27. // Enable the audio shield and set the output volume.
  28. audioShield.enable();
  29. audioShield.inputSelect(myInput);
  30. audioShield.volume(60);
  31. }
  32. elapsedMillis volmsec=0;
  33. void loop() {
  34. // every 50 ms, adjust the volume
  35. if (volmsec > 50) {
  36. float vol = analogRead(15);
  37. vol = vol / 10.24;
  38. audioShield.volume(vol);
  39. volmsec = 0;
  40. }
  41. }