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.

WavFilePlayerUSB.ino 2.2KB

8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <SD.h>
  5. #include <SerialFlash.h>
  6. AudioPlaySdWav playWav1;
  7. AudioOutputUSB audioOutput; // must set Tools > USB Type to Audio
  8. AudioOutputAnalog dac;
  9. AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
  10. AudioConnection patchCord2(playWav1, 1, audioOutput, 1);
  11. AudioConnection patchCord3(playWav1, 0, dac, 0);
  12. // Use these with the Teensy Audio Shield
  13. #define SDCARD_CS_PIN 10
  14. #define SDCARD_MOSI_PIN 7
  15. #define SDCARD_SCK_PIN 14
  16. // Use these with the Teensy 3.5 & 3.6 SD card
  17. //#define SDCARD_CS_PIN BUILTIN_SDCARD
  18. //#define SDCARD_MOSI_PIN 11 // not actually used
  19. //#define SDCARD_SCK_PIN 13 // not actually used
  20. // Use these for the SD+Wiz820 or other adaptors
  21. //#define SDCARD_CS_PIN 4
  22. //#define SDCARD_MOSI_PIN 11
  23. //#define SDCARD_SCK_PIN 13
  24. void setup() {
  25. Serial.begin(9600);
  26. // Audio connections require memory to work. For more
  27. // detailed information, see the MemoryAndCpuUsage example
  28. AudioMemory(20);
  29. SPI.setMOSI(SDCARD_MOSI_PIN);
  30. SPI.setSCK(SDCARD_SCK_PIN);
  31. if (!(SD.begin(SDCARD_CS_PIN))) {
  32. // stop here, but print a message repetitively
  33. while (1) {
  34. Serial.println("Unable to access the SD card");
  35. delay(500);
  36. }
  37. }
  38. }
  39. void playFile(const char *filename)
  40. {
  41. playWav1.play(filename);
  42. // A brief delay for the library read WAV info
  43. delay(5);
  44. // Simply wait for the file to finish playing.
  45. while (playWav1.isPlaying()) {
  46. }
  47. }
  48. void loop() {
  49. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  50. delay(500);
  51. playFile("SDTEST2.WAV");
  52. delay(500);
  53. playFile("SDTEST3.WAV");
  54. delay(500);
  55. playFile("SDTEST4.WAV");
  56. delay(1500);
  57. }
  58. // A known problem occurs on Macintosh computers, where the Mac's driver
  59. // does not seem to be able to adapt and transmit horribly distorted
  60. // audio to Teensy after a matter of minutes. An imperfect workaround
  61. // can be enabled by editing usb_audio.cpp. Find and uncomment
  62. // "#define MACOSX_ADAPTIVE_LIMIT". More detailed info is available here:
  63. // https://forum.pjrc.com/threads/34855-Distorted-audio-when-using-USB-input-on-Teensy-3-1?p=110392&viewfull=1#post110392