Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

67 lines
1.6KB

  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 <SPI.h>
  7. #include <SD.h>
  8. #include <SerialFlash.h>
  9. const int myInput = AUDIO_INPUT_LINEIN;
  10. // const int myInput = AUDIO_INPUT_MIC;
  11. // Create the Audio components. These should be created in the
  12. // order data flows, inputs/sources -> processing -> outputs
  13. //
  14. AudioInputI2S audioInput; // audio shield: mic or line-in
  15. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  16. // Create Audio connections between the components
  17. //
  18. AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
  19. AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through
  20. // Create an object to control the audio shield.
  21. //
  22. AudioControlSGTL5000 audioShield;
  23. void setup() {
  24. // Audio connections require memory to work. For more
  25. // detailed information, see the MemoryAndCpuUsage example
  26. AudioMemory(4);
  27. // Enable the audio shield and set the output volume.
  28. audioShield.enable();
  29. audioShield.inputSelect(myInput);
  30. audioShield.volume(0.5);
  31. }
  32. elapsedMillis chgMsec=0;
  33. float lastBal=1024;
  34. void loop() {
  35. // every 10 ms, check for adjustment
  36. if (chgMsec > 10) {
  37. float bal1=analogRead(15);
  38. bal1=((bal1-512)/512);
  39. bal1=(int)bal1;
  40. if(lastBal!=bal1)
  41. {
  42. if(bal1<0)
  43. { // leaning toward left...
  44. audioShield.dacVolume(1,1+bal1);
  45. } else if(bal1>0) { // to the right
  46. audioShield.dacVolume(1-bal1,1);
  47. } else { // middle
  48. audioShield.dacVolume(1);
  49. }
  50. lastBal=bal1;
  51. }
  52. chgMsec = 0;
  53. }
  54. }