Advertisement
pleasedontcode

Audio Control rev_03

Sep 20th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Audio Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-09-20 20:31:05
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Play Track 1.  play random track between 2 and 5. */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* play track for 3 minutes.  Shut down for 2 minutes */
  23.     /* then loop */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SoftwareSerial.h>
  28. #include <DFRobotDFPlayerMini.h>    //https://github.com/DFRobot/DFRobotDFPlayerMini
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34. void playTracks(void);
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t LED_LED_PIN_D2        = 2;
  38.  
  39. /***** DEFINITION OF Software Serial *****/
  40. const uint8_t DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_TX_A0     = A0;
  41. const uint8_t DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_RX_A1     = A1;
  42. SoftwareSerial DFPlayer_DFPlayerMini_Serial(DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_RX_A1, DFPlayer_DFPlayerMini_Serial_PIN_SERIAL_TX_A0);
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool    LED_LED_PIN_D2_rawData      = 0;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. /***** used to store data after characteristic curve transformation *****/
  50. float   LED_LED_PIN_D2_phyData      = 0.0;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. // Instantiate the DFPlayer object
  54. DFRobotDFPlayerMini myDFPlayer; // Correct initialization of DFPlayer object
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.     pinMode(LED_LED_PIN_D2, OUTPUT);
  60.  
  61.     // Initialize software serial for DFPlayer
  62.     DFPlayer_DFPlayerMini_Serial.begin(9600);
  63.  
  64.     // Initialize the DFPlayer
  65.     if (!myDFPlayer.begin(DFPlayer_DFPlayerMini_Serial, true, true)) { // Use serial to communicate with mp3
  66.         Serial.println(F("Unable to begin:"));
  67.         Serial.println(F("1. Please recheck the connection!"));
  68.         Serial.println(F("2. Please insert the SD card!"));
  69.         while(true); // Loop forever if initialization fails
  70.     }
  71.     Serial.println(F("DFPlayer Mini online."));
  72.     myDFPlayer.volume(10); // Set volume value (0~30)
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.     playTracks(); // Call the function to play tracks
  79. }
  80.  
  81. void playTracks()
  82. {
  83.     // Play track 1
  84.     myDFPlayer.play(1); // Play track 1
  85.     delay(180000); // Play for 3 minutes (180000 milliseconds)
  86.  
  87.     // Play a random track between 2 and 5
  88.     int randomTrack = random(2, 6); // Generate a random number between 2 and 5
  89.     myDFPlayer.play(randomTrack); // Play the random track
  90.     delay(180000); // Play for 3 minutes (180000 milliseconds)
  91.  
  92.     // Shut down for 2 minutes
  93.     myDFPlayer.stop(); // Stop playing
  94.     delay(120000); // Wait for 2 minutes (120000 milliseconds)
  95.  
  96.     // Loop back to the beginning of the function to repeat the process
  97.     playTracks(); // Call the function again to loop
  98. }
  99.  
  100. void updateOutputs()
  101. {
  102.     digitalWrite(LED_LED_PIN_D2, LED_LED_PIN_D2_rawData);
  103. }
  104.  
  105. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement