您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

StereoPeakMeter.ino 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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(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. }