Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

WM8731MikroSine.ino 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // When using AudioInputI2Sslave & AudioOutputI2Sslave with MikroE-506,
  7. // the sample rate will be the crystal frequency divided by 256. The
  8. // MikroE-506 comes with a 12.288 MHz crystal, for 48 kHz sample rate.
  9. // To get 44.1 kHz (as expected by the Teensy Audio Library) the crystal
  10. // should be replaced with 11.2896 MHz.
  11. //
  12. // Recommended connections:
  13. //
  14. // MikroE Teensy 3 Teensy 4
  15. // ------ -------- --------
  16. // SCK 9 21
  17. // MISO 13 8
  18. // MOSI 22 7
  19. // ADCL 23 20 (yes, ADCL & DACL connect together)
  20. // DACL 23 20
  21. // SDA 18 18
  22. // SCL 19 19
  23. // 3.3V +3.3V +3.3V
  24. // GND GND GND
  25. //
  26. // For connection using I2S master mode (WM8731 in slave mode, with MCLK):
  27. // https://forum.pjrc.com/threads/53854?p=198733&viewfull=1#post198733
  28. // https://forum.pjrc.com/threads/55334?p=201494&viewfull=1#post201494
  29. //
  30. // This example code is in the public domain.
  31. #include <Audio.h>
  32. #include <Wire.h>
  33. #include <SPI.h>
  34. #include <SD.h>
  35. #include <SerialFlash.h>
  36. // GUItool: begin automatically generated code
  37. AudioSynthWaveform waveform1; //xy=245,160
  38. AudioInputI2Sslave i2sslave1; //xy=265,252
  39. AudioOutputI2Sslave i2sslave2; //xy=429,158
  40. AudioAnalyzeRMS rms2; //xy=436,323
  41. AudioAnalyzeRMS rms1; //xy=444,265
  42. AudioConnection patchCord1(waveform1, 0, i2sslave2, 0);
  43. AudioConnection patchCord2(waveform1, 0, i2sslave2, 1);
  44. AudioConnection patchCord3(i2sslave1, 0, rms1, 0);
  45. AudioConnection patchCord4(i2sslave1, 1, rms2, 0);
  46. AudioControlWM8731master wm8731m1; //xy=292,379
  47. // GUItool: end automatically generated code
  48. void setup() {
  49. delay(1000); // allow the WM7831 extra time to power up
  50. wm8731m1.enable();
  51. AudioMemory(15);
  52. waveform1.begin(WAVEFORM_SINE);
  53. waveform1.frequency(440);
  54. waveform1.amplitude(0.9);
  55. wm8731m1.volume(0.50);
  56. wm8731m1.inputSelect(AUDIO_INPUT_MIC);
  57. // wm8731m1.inputSelect(AUDIO_INPUT_LINEIN); // not connected on MikroE-506
  58. }
  59. elapsedMillis msec;
  60. // Print a simple level meter
  61. void loop() {
  62. if (msec > 40) {
  63. if (rms1.available() && rms2.available()) {
  64. msec = 0;
  65. int level_left = rms1.read() * 30.0;
  66. int level_right = rms2.read() * 30.0;
  67. printchar(' ', 30 - level_left);
  68. printchar('<', level_left);
  69. Serial.print("||");
  70. printchar('>', level_right);
  71. Serial.println();
  72. }
  73. }
  74. }
  75. void printchar(char c, int num) {
  76. for (int i=0; i < num; i++) {
  77. Serial.write(c);
  78. }
  79. }