PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

103 rindas
3.6KB

  1. /***************************************************
  2. This is an example for the Adafruit VS1053 Codec Breakout
  3. Designed specifically to work with the Adafruit VS1053 Codec Breakout
  4. ----> https://www.adafruit.com/products/1381
  5. Adafruit invests time and resources providing this open source code,
  6. please support Adafruit and open-source hardware by purchasing
  7. products from Adafruit!
  8. Written by Limor Fried/Ladyada for Adafruit Industries.
  9. BSD license, all text above must be included in any redistribution
  10. ****************************************************/
  11. // include SPI, MP3 and SD libraries
  12. #include <SPI.h>
  13. #include <Adafruit_VS1053.h>
  14. #include <SD.h>
  15. // define the pins used
  16. //#define CLK 13 // SPI Clock, shared with SD card
  17. //#define MISO 12 // Input data, from VS1053/SD card
  18. //#define MOSI 11 // Output data, to VS1053/SD card
  19. // Connect CLK, MISO and MOSI to hardware SPI pins.
  20. // See http://arduino.cc/en/Reference/SPI "Connections"
  21. // These are the pins used for the breakout example
  22. #define BREAKOUT_RESET 9 // VS1053 reset pin (output)
  23. #define BREAKOUT_CS 10 // VS1053 chip select pin (output)
  24. #define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
  25. // These are the pins used for the music maker shield
  26. #define SHIELD_CS 7 // VS1053 chip select pin (output)
  27. #define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
  28. // These are common pins between breakout and shield
  29. #define CARDCS 4 // Card chip select pin
  30. // DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
  31. #define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
  32. Adafruit_VS1053_FilePlayer musicPlayer =
  33. // create breakout-example object!
  34. Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  35. // create shield-example object!
  36. //Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
  37. void setup() {
  38. Serial.begin(9600);
  39. Serial.println("Adafruit VS1053 Simple Test");
  40. if (! musicPlayer.begin()) { // initialise the music player
  41. Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
  42. while (1);
  43. }
  44. Serial.println(F("VS1053 found"));
  45. SD.begin(CARDCS); // initialise the SD card
  46. // Set volume for left, right channels. lower numbers == louder volume!
  47. musicPlayer.setVolume(20,20);
  48. // Timer interrupts are not suggested, better to use DREQ interrupt!
  49. //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int
  50. // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  51. // audio playing
  52. musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
  53. // Play one file, don't return until complete
  54. Serial.println(F("Playing track 001"));
  55. musicPlayer.playFullFile("track001.mp3");
  56. // Play another file in the background, REQUIRES interrupts!
  57. Serial.println(F("Playing track 002"));
  58. musicPlayer.startPlayingFile("track002.mp3");
  59. }
  60. void loop() {
  61. // File is playing in the background
  62. if (musicPlayer.stopped()) {
  63. Serial.println("Done playing music");
  64. while (1);
  65. }
  66. if (Serial.available()) {
  67. char c = Serial.read();
  68. // if we get an 's' on the serial console, stop!
  69. if (c == 's') {
  70. musicPlayer.stopPlaying();
  71. }
  72. // if we get an 'p' on the serial console, pause/unpause!
  73. if (c == 'p') {
  74. if (! musicPlayer.paused()) {
  75. Serial.println("Paused");
  76. musicPlayer.pausePlaying(true);
  77. } else {
  78. Serial.println("Resumed");
  79. musicPlayer.pausePlaying(false);
  80. }
  81. }
  82. }
  83. delay(100);
  84. }