Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

63 lines
1.7KB

  1. // DAC balance example: Will influence both HP & LO outputs.
  2. #include <Audio.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. AudioInputI2S audioInput; // audio shield: mic or line-in
  11. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  12. // Create Audio connections between the components
  13. //
  14. AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
  15. AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through
  16. // Create an object to control the audio shield.
  17. //
  18. AudioControlSGTL5000 audioShield;
  19. void setup() {
  20. // Audio connections require memory to work. For more
  21. // detailed information, see the MemoryAndCpuUsage example
  22. AudioMemory(4);
  23. // Enable the audio shield and set the output volume.
  24. audioShield.enable();
  25. audioShield.inputSelect(myInput);
  26. audioShield.volume(75);
  27. audioShield.unmuteLineout();
  28. }
  29. elapsedMillis chgMsec=0;
  30. float lastBal=1024;
  31. void loop() {
  32. // every 10 ms, check for adjustment the balance & vol
  33. if (chgMsec > 10) { // more regular updates for actual changes seems better.
  34. float bal1=analogRead(15);
  35. bal1=((bal1-512)/512)*100;
  36. bal1=(int)bal1;
  37. if(lastBal!=bal1)
  38. {
  39. if(bal1<0)
  40. { // leaning toward left...
  41. audioShield.dac_vol(100,100+bal1);
  42. } else if(bal1>0) { // to the right
  43. audioShield.dac_vol(100-bal1,100);
  44. } else { // middle
  45. audioShield.dac_vol(100);
  46. }
  47. lastBal=bal1;
  48. }
  49. chgMsec = 0;
  50. }
  51. }