Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

116 rindas
3.3KB

  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. AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
  38. AudioConnection patchCord2(playWav1, 1, audioOutput, 1);
  39. AudioControlSGTL5000 sgtl5000_1;
  40. // Use these with the Teensy Audio Shield
  41. #define SDCARD_CS_PIN 10
  42. #define SDCARD_MOSI_PIN 7
  43. #define SDCARD_SCK_PIN 14
  44. // Use these with the Teensy 3.5 & 3.6 SD card
  45. //#define SDCARD_CS_PIN BUILTIN_SDCARD
  46. //#define SDCARD_MOSI_PIN 11 // not actually used
  47. //#define SDCARD_SCK_PIN 13 // not actually used
  48. // Use these for the SD+Wiz820 or other adaptors
  49. //#define SDCARD_CS_PIN 4
  50. //#define SDCARD_MOSI_PIN 11
  51. //#define SDCARD_SCK_PIN 13
  52. void setup() {
  53. Serial.begin(9600);
  54. // Audio connections require memory to work. For more
  55. // detailed information, see the MemoryAndCpuUsage example
  56. AudioMemory(8);
  57. // Comment these out if not using the audio adaptor board.
  58. // This may wait forever if the SDA & SCL pins lack
  59. // pullup resistors
  60. sgtl5000_1.enable();
  61. sgtl5000_1.volume(0.5);
  62. SPI.setMOSI(SDCARD_MOSI_PIN);
  63. SPI.setSCK(SDCARD_SCK_PIN);
  64. if (!(SD.begin(SDCARD_CS_PIN))) {
  65. // stop here, but print a message repetitively
  66. while (1) {
  67. Serial.println("Unable to access the SD card");
  68. delay(500);
  69. }
  70. }
  71. }
  72. void playFile(const char *filename)
  73. {
  74. Serial.print("Playing file: ");
  75. Serial.println(filename);
  76. // Start playing the file. This sketch continues to
  77. // run while the file plays.
  78. playWav1.play(filename);
  79. // A brief delay for the library read WAV info
  80. delay(5);
  81. // Simply wait for the file to finish playing.
  82. while (playWav1.isPlaying()) {
  83. // uncomment these lines if you audio shield
  84. // has the optional volume pot soldered
  85. //float vol = analogRead(15);
  86. //vol = vol / 1024;
  87. // sgtl5000_1.volume(vol);
  88. }
  89. }
  90. void loop() {
  91. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  92. delay(500);
  93. playFile("SDTEST2.WAV");
  94. delay(500);
  95. playFile("SDTEST3.WAV");
  96. delay(500);
  97. playFile("SDTEST4.WAV");
  98. delay(1500);
  99. }