Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Simple MP3 file player example
  2. //
  3. // https://forum.pjrc.com/threads/27059-MP3-Player-Lib-with-example?p=101537&viewfull=1#post101537
  4. //
  5. // Requires the prop-shield and Teensy 3.2 or 3.1
  6. // This example code is in the public domain.
  7. #include <Audio.h>
  8. #include <Wire.h>
  9. #include <SPI.h>
  10. #include <SD.h>
  11. #include <SerialFlash.h>
  12. #include <play_sd_mp3.h> // https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
  13. //#include <play_sd_aac.h>
  14. // GUItool: begin automatically generated code
  15. //AudioPlaySdWav playSdWav1; //xy=154,422
  16. AudioPlaySdMp3 playMp31; //xy=154,422
  17. AudioMixer4 mixer1; //xy=327,432
  18. AudioOutputAnalog dac1; //xy=502,412
  19. AudioConnection patchCord1(playMp31, 0, mixer1, 0);
  20. AudioConnection patchCord2(playMp31, 1, mixer1, 1);
  21. AudioConnection patchCord3(mixer1, dac1);
  22. // GUItool: end automatically generated code
  23. #define PROP_AMP_ENABLE 5
  24. #define FLASH_CHIP_SELECT 6
  25. //#define FLASH_CHIP_SELECT 21 // Arduino 101 built-in SPI Flash
  26. void setup() {
  27. Serial.begin(9600);
  28. AudioMemory(8); //4
  29. delay(2000);
  30. // Start SerialFlash
  31. if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
  32. while (1) {
  33. Serial.println ("Cannot access SPI Flash chip");
  34. delay (1000);
  35. }
  36. }
  37. //Set Volume
  38. mixer1.gain(0, 0.5);
  39. mixer1.gain(1, 0.5);
  40. //Start Amplifier
  41. pinMode(PROP_AMP_ENABLE, OUTPUT);
  42. digitalWrite(PROP_AMP_ENABLE, HIGH); // Enable Amplifier
  43. }
  44. void playFile(const char *filename)
  45. {
  46. SerialFlashFile ff = SerialFlash.open(filename);
  47. Serial.print("Playing file: ");
  48. Serial.println(filename);
  49. uint32_t sz = ff.size();
  50. uint32_t pos = ff.getFlashAddress();
  51. // Start playing the file. This sketch continues to
  52. // run while the file plays.
  53. playMp31.play(pos,sz);
  54. // Simply wait for the file to finish playing.
  55. while (playMp31.isPlaying()) {
  56. yield();
  57. }
  58. }
  59. void loop() {
  60. playFile("rain.mp3");
  61. delay(1000);
  62. }