您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.4KB

  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 audio adaptor board
  13. #define SDCARD_CS_PIN 10
  14. #define SDCARD_MOSI_PIN 7
  15. #define SDCARD_SCK_PIN 14
  16. void setup() {
  17. Serial.begin(9600);
  18. // Audio connections require memory to work. For more
  19. // detailed information, see the MemoryAndCpuUsage example
  20. AudioMemory(20);
  21. SPI.setMOSI(SDCARD_MOSI_PIN);
  22. SPI.setSCK(SDCARD_SCK_PIN);
  23. if (!(SD.begin(SDCARD_CS_PIN))) {
  24. // stop here, but print a message repetitively
  25. while (1) {
  26. Serial.println("Unable to access the SD card");
  27. delay(500);
  28. }
  29. }
  30. }
  31. void playFile(const char *filename)
  32. {
  33. playWav1.play(filename);
  34. // A brief delay for the library read WAV info
  35. delay(5);
  36. // Simply wait for the file to finish playing.
  37. while (playWav1.isPlaying()) {
  38. }
  39. }
  40. void loop() {
  41. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  42. delay(500);
  43. playFile("SDTEST2.WAV");
  44. delay(500);
  45. playFile("SDTEST3.WAV");
  46. delay(500);
  47. playFile("SDTEST4.WAV");
  48. delay(1500);
  49. }