I_Mihalache_AudioPlayer.ino 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. }
  63. //
  64. //void playFile(const char *filename)
  65. //{
  66. // Serial.print("Playing file: ");
  67. // Serial.println(filename);
  68. //
  69. // // Start playing the file. This sketch continues to
  70. // // run while the file plays.
  71. // playWav1.play(filename);
  72. //
  73. // // A brief delay for the library read WAV info
  74. // delay(5);
  75. //
  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 printLDR(){
  86. Serial.print(analogRead(A3));
  87. Serial.print(" ");
  88. Serial.print(digitalRead(16));
  89. Serial.print(" ");
  90. Serial.print(analogRead(A7));
  91. Serial.print(" ");
  92. Serial.print(digitalRead(20));
  93. Serial.println();
  94. }
  95. void loop() {
  96. int brightness;
  97. /* Simple loop to ramp up brightness */
  98. for (brightness = 0; brightness <= 255; brightness++) {
  99. /* Update DMX channel 1 to new brightness */
  100. DmxSimple.write(1, brightness);
  101. printLDR();
  102. /* Small delay to slow down the ramping */
  103. delay(10);
  104. }
  105. delay(100);
  106. // playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  107. // delay(500);
  108. // playFile("SDTEST2.WAV");
  109. // delay(500);
  110. // playFile("SDTEST3.WAV");
  111. // delay(500);
  112. // playFile("SDTEST4.WAV");
  113. // delay(1500);
  114. }