Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

StereoPeakMeter.ino 1.5KB

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