No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

119 líneas
3.4KB

  1. // Simple WAV file player example
  2. //
  3. // Three types of output may be used, by configuring the code below.
  4. //
  5. // 1: Digital I2S - Normally used with the audio shield:
  6. // http://www.pjrc.com/store/teensy3_audio.html
  7. //
  8. // 2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter
  9. // https://www.oshpark.com/shared_projects/KcDBKHta
  10. //
  11. // 3: Analog DAC - Connect the DAC pin to an amplified speaker
  12. // http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog
  13. //
  14. // To configure the output type, first uncomment one of the three
  15. // output objects. If not using the audio shield, comment out
  16. // the sgtl5000_1 lines in setup(), so it does not wait forever
  17. // trying to configure the SGTL5000 codec chip.
  18. //
  19. // The SD card may connect to different pins, depending on the
  20. // hardware you are using. Uncomment or configure the SD card
  21. // pins to match your hardware.
  22. //
  23. // Data files to put on your SD card can be downloaded here:
  24. // http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
  25. //
  26. // This example code is in the public domain.
  27. #include <Audio.h>
  28. #include <Wire.h>
  29. #include <SPI.h>
  30. #include <SD.h>
  31. #include <SerialFlash.h>
  32. AudioPlaySdWav playWav1;
  33. // Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
  34. AudioOutputI2S audioOutput;
  35. //AudioOutputSPDIF audioOutput;
  36. //AudioOutputAnalog audioOutput;
  37. //On Teensy LC, use this for the Teensy Audio Shield:
  38. //AudioOutputI2Sslave audioOutput;
  39. AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
  40. AudioConnection patchCord2(playWav1, 1, audioOutput, 1);
  41. AudioControlSGTL5000 sgtl5000_1;
  42. // Use these with the Teensy Audio Shield
  43. #define SDCARD_CS_PIN 10
  44. #define SDCARD_MOSI_PIN 7
  45. #define SDCARD_SCK_PIN 14
  46. // Use these with the Teensy 3.5 & 3.6 SD card
  47. //#define SDCARD_CS_PIN BUILTIN_SDCARD
  48. //#define SDCARD_MOSI_PIN 11 // not actually used
  49. //#define SDCARD_SCK_PIN 13 // not actually used
  50. // Use these for the SD+Wiz820 or other adaptors
  51. //#define SDCARD_CS_PIN 4
  52. //#define SDCARD_MOSI_PIN 11
  53. //#define SDCARD_SCK_PIN 13
  54. void setup() {
  55. Serial.begin(9600);
  56. // Audio connections require memory to work. For more
  57. // detailed information, see the MemoryAndCpuUsage example
  58. AudioMemory(8);
  59. // Comment these out if not using the audio adaptor board.
  60. // This may wait forever if the SDA & SCL pins lack
  61. // pullup resistors
  62. sgtl5000_1.enable();
  63. sgtl5000_1.volume(0.5);
  64. SPI.setMOSI(SDCARD_MOSI_PIN);
  65. SPI.setSCK(SDCARD_SCK_PIN);
  66. if (!(SD.begin(SDCARD_CS_PIN))) {
  67. // stop here, but print a message repetitively
  68. while (1) {
  69. Serial.println("Unable to access the SD card");
  70. delay(500);
  71. }
  72. }
  73. }
  74. void playFile(const char *filename)
  75. {
  76. Serial.print("Playing file: ");
  77. Serial.println(filename);
  78. // Start playing the file. This sketch continues to
  79. // run while the file plays.
  80. playWav1.play(filename);
  81. // A brief delay for the library read WAV info
  82. delay(5);
  83. // Simply wait for the file to finish playing.
  84. while (playWav1.isPlaying()) {
  85. // uncomment these lines if you audio shield
  86. // has the optional volume pot soldered
  87. //float vol = analogRead(15);
  88. //vol = vol / 1024;
  89. // sgtl5000_1.volume(vol);
  90. }
  91. }
  92. void loop() {
  93. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  94. delay(500);
  95. playFile("SDTEST2.WAV");
  96. delay(500);
  97. playFile("SDTEST3.WAV");
  98. delay(500);
  99. playFile("SDTEST4.WAV");
  100. delay(1500);
  101. }