Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

110 Zeilen
3.1KB

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