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.

80 linhas
2.1KB

  1. // Simple sine wave & input level test for WM8731 Audio Codec Board
  2. //
  3. // Requires the MikroElektronika Audio Codec board or similar hardware
  4. // http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
  5. //
  6. // Recommended connections:
  7. //
  8. // Mikroe Teensy 3.1
  9. // ------ ----------
  10. // SCK 9
  11. // MISO 13
  12. // MOSI 22
  13. // ADCL 23 (yes, ADCL & DACL connect together)
  14. // DACL 23
  15. // SDA 18
  16. // SCL 19
  17. // 3.3V +3.3V
  18. // GND GND
  19. //
  20. // This example code is in the public domain.
  21. #include <Audio.h>
  22. #include <Wire.h>
  23. #include <SPI.h>
  24. #include <SD.h>
  25. #include <SerialFlash.h>
  26. // GUItool: begin automatically generated code
  27. AudioSynthWaveform waveform1; //xy=245,160
  28. AudioInputI2Sslave i2sslave1; //xy=265,252
  29. AudioOutputI2Sslave i2sslave2; //xy=429,158
  30. AudioAnalyzeRMS rms2; //xy=436,323
  31. AudioAnalyzeRMS rms1; //xy=444,265
  32. AudioConnection patchCord1(waveform1, 0, i2sslave2, 0);
  33. AudioConnection patchCord2(waveform1, 0, i2sslave2, 1);
  34. AudioConnection patchCord3(i2sslave1, 0, rms1, 0);
  35. AudioConnection patchCord4(i2sslave1, 1, rms2, 0);
  36. AudioControlWM8731master wm8731m1; //xy=292,379
  37. // GUItool: end automatically generated code
  38. void setup() {
  39. wm8731m1.enable();
  40. AudioMemory(15);
  41. waveform1.begin(WAVEFORM_SINE);
  42. waveform1.frequency(440);
  43. waveform1.amplitude(0.9);
  44. wm8731m1.volume(0.50);
  45. wm8731m1.inputSelect(AUDIO_INPUT_MIC);
  46. // wm8731m1.inputSelect(AUDIO_INPUT_LINEIN); // not connected on MikroE-516
  47. }
  48. elapsedMillis msec;
  49. // Print a simple level meter
  50. void loop() {
  51. if (msec > 40) {
  52. if (rms1.available() && rms2.available()) {
  53. msec = 0;
  54. int level_left = rms1.read() * 30.0;
  55. int level_right = rms2.read() * 30.0;
  56. printchar(' ', 30 - level_left);
  57. printchar('<', level_left);
  58. Serial.print("||");
  59. printchar('>', level_right);
  60. Serial.println();
  61. }
  62. }
  63. }
  64. void printchar(char c, int num) {
  65. for (int i=0; i < num; i++) {
  66. Serial.write(c);
  67. }
  68. }