Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

63 rindas
1.6KB

  1. // HP balance example: Will influence only HP output.
  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. // Just connecting in to out
  14. AudioConnection c1(audioInput, 0, audioOutput, 0); // left connection
  15. AudioConnection c2(audioInput, 1, audioOutput, 1); // right connection
  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(60);
  27. audioShield.unmuteLineout();
  28. }
  29. elapsedMillis chgMsec=0;
  30. float lastBal=1024;
  31. float vol1=75;
  32. void loop() {
  33. // every 10 ms, check for adjustment the balance & vol
  34. if (chgMsec > 10) { // more regular updates for actual changes seems better.
  35. float bal1=analogRead(15);
  36. bal1=((bal1-512)/512)*100;
  37. bal1=(int)bal1;
  38. if(lastBal!=bal1)
  39. {
  40. if(bal1<0)
  41. {
  42. audioShield.volume(vol1,(vol1/100)*(100+bal1));
  43. } else {
  44. audioShield.volume((vol1/100)*(100-bal1),vol1);
  45. }
  46. lastBal=bal1;
  47. }
  48. chgMsec = 0;
  49. }
  50. }