您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

66 行
1.6KB

  1. /* HP balance example: Will influence only HP output.
  2. This example code is in the public domain
  3. */
  4. #include <Audio.h>
  5. #include <Wire.h>
  6. #include <SD.h>
  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. // Just connecting in to out
  16. AudioConnection c1(audioInput, 0, audioOutput, 0); // left connection
  17. AudioConnection c2(audioInput, 1, audioOutput, 1); // right connection
  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(4);
  25. // Enable the audio shield and set the output volume.
  26. audioShield.enable();
  27. audioShield.inputSelect(myInput);
  28. audioShield.volume(60);
  29. audioShield.unmuteLineout();
  30. }
  31. elapsedMillis chgMsec=0;
  32. float lastBal=1024;
  33. float vol1=75;
  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. float bal1=analogRead(15);
  38. bal1=((bal1-512)/512)*100;
  39. bal1=(int)bal1;
  40. if(lastBal!=bal1)
  41. {
  42. if(bal1<0)
  43. {
  44. audioShield.volume(vol1,(vol1/100)*(100+bal1));
  45. } else {
  46. audioShield.volume((vol1/100)*(100-bal1),vol1);
  47. }
  48. lastBal=bal1;
  49. }
  50. chgMsec = 0;
  51. }
  52. }