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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <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. AudioInputI2S audioInput; // audio shield: mic or line-in
  12. AudioAnalyzePeak peak_L;
  13. AudioAnalyzePeak peak_R;
  14. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  15. AudioConnection c1(audioInput,0,peak_L,0);
  16. AudioConnection c2(audioInput,1,peak_R,0);
  17. AudioConnection c3(audioInput,0,audioOutput,0);
  18. AudioConnection c4(audioInput,1,audioOutput,1);
  19. AudioControlSGTL5000 audioShield;
  20. void setup() {
  21. AudioMemory(6);
  22. audioShield.enable();
  23. audioShield.inputSelect(myInput);
  24. audioShield.volume(0.5);
  25. Serial.begin(9600);
  26. }
  27. // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.
  28. elapsedMillis fps;
  29. uint8_t cnt=0;
  30. void loop() {
  31. if(fps > 24) {
  32. if (peak_L.available() && peak_R.available()) {
  33. fps=0;
  34. uint8_t leftPeak=peak_L.read() * 30.0;
  35. uint8_t rightPeak=peak_R.read() * 30.0;
  36. for(cnt=0;cnt<30-leftPeak;cnt++) {
  37. Serial.print(" ");
  38. }
  39. while(cnt++<30) {
  40. Serial.print("<");
  41. }
  42. Serial.print("||");
  43. for(cnt=0;cnt<rightPeak;cnt++) {
  44. Serial.print(">");
  45. }
  46. while(cnt++<30) {
  47. Serial.print(" ");
  48. }
  49. Serial.println();
  50. }
  51. }
  52. }