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.

54 lines
1.5KB

  1. /* Stereo peak meter example, assumes Audio adapter but just uses terminal so no more parts required.
  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. AudioInputI2S audioInput; // audio shield: mic or line-in
  10. AudioPeak peak_L;
  11. AudioPeak peak_R;
  12. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  13. AudioConnection c1(audioInput,0,peak_L,0);
  14. AudioConnection c2(audioInput,1,peak_R,0);
  15. AudioConnection c3(audioInput,0,audioOutput,0);
  16. AudioConnection c4(audioInput,1,audioOutput,1);
  17. AudioControlSGTL5000 audioShield;
  18. void setup() {
  19. AudioMemory(6);
  20. audioShield.enable();
  21. audioShield.inputSelect(myInput);
  22. audioShield.volume(0.75);
  23. audioShield.unmuteLineout();
  24. Serial.begin(Serial.baud());
  25. }
  26. elapsedMillis fps;
  27. uint8_t cnt=0;
  28. void loop() {
  29. if(fps>24) { // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.
  30. Serial.println();
  31. fps=0;
  32. uint8_t leftPeak=peak_L.Dpp()/2184.5321; // 65536 / 2184.5321 ~ 30.
  33. for(cnt=0;cnt<30-leftPeak;cnt++) Serial.print(" ");
  34. while(cnt++<30) Serial.print("<");
  35. Serial.print("||");
  36. uint8_t rightPeak=peak_R.Dpp()/2184.5321;
  37. for(cnt=0;cnt<rightPeak;cnt++) Serial.print(">");
  38. while(cnt++<30) Serial.print(" ");
  39. peak_L.begin(); // no need to call .stop if all you want
  40. peak_R.begin(); // is to zero it.
  41. }
  42. }