Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

StereoPeakMeter.ino 1.5KB

10 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.5);
  24. Serial.begin(9600);
  25. }
  26. // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.
  27. elapsedMillis fps;
  28. uint8_t cnt=0;
  29. void loop() {
  30. if(fps > 24) {
  31. if (peak_L.available() && peak_R.available()) {
  32. fps=0;
  33. uint8_t leftPeak=peak_L.read() * 30.0;
  34. uint8_t rightPeak=peak_R.read() * 30.0;
  35. for(cnt=0;cnt<30-leftPeak;cnt++) {
  36. Serial.print(" ");
  37. }
  38. while(cnt++<30) {
  39. Serial.print("<");
  40. }
  41. Serial.print("||");
  42. for(cnt=0;cnt<rightPeak;cnt++) {
  43. Serial.print(">");
  44. }
  45. while(cnt++<30) {
  46. Serial.print(" ");
  47. }
  48. Serial.println();
  49. }
  50. }
  51. }