Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

51 lines
1.3KB

  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SD.h>
  4. const int myInput = AUDIO_INPUT_LINEIN;
  5. //const int myInput = AUDIO_INPUT_MIC;
  6. // Create the Audio components. These should be created in the
  7. // order data flows, inputs/sources -> processing -> outputs
  8. //
  9. //AudioInputAnalog analogPinInput(16); // analog A2 (pin 16)
  10. AudioInputI2S audioInput; // audio shield: mic or line-in
  11. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  12. AudioOutputPWM pwmOutput; // audio output with PWM on pins 3 & 4
  13. // Create Audio connections between the components
  14. //
  15. AudioConnection c1(audioInput, 0, audioOutput, 0);
  16. AudioConnection c2(audioInput, 1, audioOutput, 1);
  17. AudioConnection c5(audioInput, 0, pwmOutput, 0);
  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(12);
  25. // Enable the audio shield and set the output volume.
  26. audioShield.enable();
  27. audioShield.inputSelect(myInput);
  28. audioShield.volume(60);
  29. }
  30. elapsedMillis volmsec=0;
  31. void loop() {
  32. // every 50 ms, adjust the volume
  33. if (volmsec > 50) {
  34. float vol = analogRead(15);
  35. vol = vol / 10.24;
  36. audioShield.volume(vol);
  37. volmsec = 0;
  38. }
  39. }