I_Mihalache_AudioPlayer.ino 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <SD.h>
  5. #include <SerialFlash.h>
  6. #include <DmxSimple.h>
  7. /* SdWav1 : sample voix |
  8. * SdWav2 : sample attente |-> mix1 -> Lout & RMS1
  9. *
  10. * SdWav3 : sample ambiance -> mix2 -> Rout & RMS2
  11. */
  12. // GUItool: begin automatically generated code
  13. AudioPlaySdWav playSdWav3; //xy=152,429
  14. AudioPlaySdWav playSdWav1; //xy=153,217
  15. AudioPlaySdWav playSdWav2; //xy=155,307
  16. AudioMixer4 mixer1; //xy=572,215
  17. AudioMixer4 mixer2; //xy=579,344
  18. AudioAnalyzeRMS rms1; //xy=875,315
  19. AudioOutputI2S i2s1; //xy=876,225
  20. AudioAnalyzeRMS rms2; //xy=876,365
  21. AudioConnection patchCord1(playSdWav3, 0, mixer2, 0);
  22. AudioConnection patchCord2(playSdWav1, 0, mixer1, 0);
  23. AudioConnection patchCord3(playSdWav2, 0, mixer1, 1);
  24. AudioConnection patchCord4(mixer1, 0, i2s1, 0);
  25. AudioConnection patchCord5(mixer1, rms1);
  26. AudioConnection patchCord6(mixer2, 0, i2s1, 1);
  27. AudioConnection patchCord7(mixer2, rms2);
  28. AudioControlSGTL5000 sgtl5000_1; //xy=573,537
  29. // GUItool: end automatically generated code
  30. // Use these with the Teensy Audio Shield
  31. #define SDCARD_CS_PIN 10
  32. #define SDCARD_MOSI_PIN 7
  33. #define SDCARD_SCK_PIN 14
  34. // Use these with the Teensy 3.5 & 3.6 SD card
  35. //#define SDCARD_CS_PIN BUILTIN_SDCARD
  36. //#define SDCARD_MOSI_PIN 11 // not actually used
  37. //#define SDCARD_SCK_PIN 13 // not actually used
  38. void setup() {
  39. Serial.begin(9600);
  40. // DmxSimple.maxChannel(4);
  41. // DmxSimple.write(4, 250);
  42. pinMode(16, INPUT);
  43. pinMode(20,INPUT);
  44. // Audio connections require memory to work. For more
  45. // detailed information, see the MemoryAndCpuUsage example
  46. AudioMemory(16);
  47. // Comment these out if not using the audio adaptor board.
  48. // This may wait forever if the SDA & SCL pins lack
  49. // pullup resistors
  50. sgtl5000_1.enable();
  51. sgtl5000_1.lineOutLevel(13); // set output to 3.16 Vpp
  52. sgtl5000_1.volume(1); //set volume to maximum
  53. SPI.setMOSI(SDCARD_MOSI_PIN);
  54. SPI.setSCK(SDCARD_SCK_PIN);
  55. if (!(SD.begin(SDCARD_CS_PIN))) {
  56. // stop here, but print a message repetitively
  57. while (1) {
  58. Serial.println("Unable to access the SD card");
  59. delay(500);
  60. }
  61. }
  62. delay(2000);
  63. }
  64. //
  65. void playFile(const char *filename)
  66. {
  67. Serial.print("Playing file: ");
  68. Serial.println(filename);
  69. // Start playing the file. This sketch continues to
  70. // run while the file plays.
  71. playSdWav1.play(filename);
  72. // A brief delay for the library read WAV info
  73. delay(5);
  74. // Simply wait for the file to finish playing.
  75. while (playSdWav1.isPlaying()) {
  76. printLDR();
  77. // uncomment these lines if you audio shield
  78. // has the optional volume pot soldered
  79. //float vol = analogRead(15);
  80. //vol = vol / 1024;
  81. // sgtl5000_1.volume(vol);
  82. }
  83. }
  84. void printLDR(){
  85. Serial.print(analogRead(A3));
  86. Serial.print(" ");
  87. Serial.print(digitalRead(16));
  88. Serial.print(" ");
  89. Serial.print(analogRead(A7));
  90. Serial.print(" ");
  91. Serial.print(digitalRead(20));
  92. Serial.println();
  93. }
  94. void loop() {
  95. delay(100);
  96. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  97. delay(500);
  98. playFile("SDTEST2.WAV");
  99. delay(500);
  100. playFile("SDTEST3.WAV");
  101. delay(500);
  102. playFile("SDTEST4.WAV");
  103. delay(1500);
  104. }