Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

balanceDAC.ino 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* DAC balance example: Will influence both HP & LO outputs.
  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. //
  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(4);
  25. // Enable the audio shield and set the output volume.
  26. audioShield.enable();
  27. audioShield.inputSelect(myInput);
  28. audioShield.volume(0.75);
  29. audioShield.unmuteLineout();
  30. }
  31. elapsedMillis chgMsec=0;
  32. float lastBal=1024;
  33. void loop() {
  34. // every 10 ms, check for adjustment
  35. if (chgMsec > 10) {
  36. float bal1=analogRead(15);
  37. bal1=((bal1-512)/512);
  38. bal1=(int)bal1;
  39. if(lastBal!=bal1)
  40. {
  41. if(bal1<0)
  42. { // leaning toward left...
  43. audioShield.dacVolume(1,1+bal1);
  44. } else if(bal1>0) { // to the right
  45. audioShield.dacVolume(1-bal1,1);
  46. } else { // middle
  47. audioShield.dacVolume(1);
  48. }
  49. lastBal=bal1;
  50. }
  51. chgMsec = 0;
  52. }
  53. }