Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

77 linhas
1.9KB

  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. void setup() {
  26. Serial.begin(9600);
  27. AudioMemory(8); //4
  28. delay(2000);
  29. // Start SerialFlash
  30. if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
  31. while (1) {
  32. Serial.println ("Cannot access SPI Flash chip");
  33. delay (1000);
  34. }
  35. }
  36. //Set Volume
  37. mixer1.gain(0, 0.5);
  38. mixer1.gain(1, 0.5);
  39. //Start Amplifier
  40. pinMode(PROP_AMP_ENABLE, OUTPUT);
  41. digitalWrite(PROP_AMP_ENABLE, HIGH); // Enable Amplifier
  42. }
  43. void playFile(const char *filename)
  44. {
  45. SerialFlashFile ff = SerialFlash.open(filename);
  46. Serial.print("Playing file: ");
  47. Serial.println(filename);
  48. uint32_t sz = ff.size();
  49. uint32_t pos = ff.getFlashAddress();
  50. // Start playing the file. This sketch continues to
  51. // run while the file plays.
  52. playMp31.play(pos,sz);
  53. // Simply wait for the file to finish playing.
  54. while (playMp31.isPlaying()) {
  55. yield();
  56. }
  57. }
  58. void loop() {
  59. playFile("rain.mp3");
  60. delay(1000);
  61. }