Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

84 lines
2.1KB

  1. // DAC balance example: Will influence both HP & LO outputs.
  2. #include <Audio.h>
  3. #include <Wire.h>
  4. #include <SD.h>
  5. #define PIN_VOLUME 0
  6. #define PIN_BALANCE 15
  7. const int myInput = AUDIO_INPUT_LINEIN;
  8. // const int myInput = AUDIO_INPUT_MIC;
  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. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  14. // Create Audio connections between the components
  15. //
  16. AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
  17. AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through
  18. // Create an object to control the audio shield.
  19. //
  20. AudioControlSGTL5000 audioShield;
  21. void setup() {
  22. // Audio connections require memory to work. For more
  23. // detailed information, see the MemoryAndCpuUsage example
  24. AudioMemory(6);
  25. // Enable the audio shield and set the output volume.
  26. audioShield.enable();
  27. audioShield.inputSelect(myInput);
  28. audioShield.volume(90);
  29. audioShield.unmuteLineout();
  30. }
  31. elapsedMillis chgMsec=0;
  32. float lastVol=1024;
  33. float lastBal=1024;
  34. void loop() {
  35. // every 10 ms, check for adjustment the balance & vol
  36. if (chgMsec > 10) { // more regular updates for actual changes seems better.
  37. #if PIN_BALANCE
  38. float bal1=analogRead(PIN_BALANCE);
  39. #else
  40. float bal1=0; // middle will be default if analog pin is not supplied
  41. #endif
  42. bal1=((bal1-512)/512)*100;
  43. bal1=(int)bal1;
  44. if(lastBal!=bal1)
  45. {
  46. if(bal1<0)
  47. { // leaning toward left...
  48. audioShield.dac_vol(100,100+bal1);
  49. } else if(bal1>0) { // to the right
  50. audioShield.dac_vol(100-bal1,100);
  51. } else { // middle
  52. audioShield.dac_vol(100);
  53. }
  54. lastBal=bal1;
  55. }
  56. #if PIN_VOLUME
  57. float vol1=analogRead(PIN_VOLUME)/10.23; // 0 - 100
  58. #else
  59. float vol1=70; // 70% output will be default if analog pin is not supplied.
  60. #endif
  61. vol1=(int)vol1;
  62. if(lastVol!=vol1)
  63. {
  64. audioShield.volume(vol1);
  65. lastVol=vol1;
  66. }
  67. chgMsec = 0;
  68. }
  69. }