Advertisement
elektronek

Jiří Sklenář - DFmini MP3 player

May 14th, 2024 (edited)
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.01 KB | Source Code | 0 0
  1. #include <SoftwareSerial.h>
  2. #define RX_PIN 8
  3. #define TX_PIN 9
  4.  
  5. SoftwareSerial mySerial(RX_PIN, TX_PIN);
  6.  
  7. void setup() {
  8.   mySerial.begin(9600);
  9.  
  10.   sendMP3cmd(0x0C,0x00);  // reset mp3 modulu
  11.   _delay_ms(50);
  12.   sendMP3cmd(0x09,0x02);  // soubory jsou na SD karte
  13.   _delay_ms(20);
  14.   sendMP3cmd(0x06,0x1F);  // nastav hlasitost
  15.   _delay_ms(20);
  16.  
  17.   sendMP3cmd(0x03,0x01);  // prehraj 1 skladbu
  18. }
  19.  
  20. void loop() {
  21.   // nic ....
  22.  
  23. }
  24.  
  25.  
  26. void sendMP3cmd(uint8_t cmd, uint16_t par)      // tvorba prikazu pro mp3 prehravac - netreba popisu - viz datasheet
  27. {
  28.   //                          CMD  ACK   MSB   LSB   CMSB  LMSB  EOF
  29.   uint8_t command[] = {0x7E, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF}; // buffer
  30.   command[3]=cmd;
  31.   command[5]=(uint8_t)(par>>8);
  32.   command[6]=(uint8_t)(par & 0x00ff);
  33.   uint16_t crc=0x0000;
  34.   for (uint8_t a=1; a <=6 ; a++) crc-=command[a];
  35.   command[7]=(uint8_t)(crc>>8);
  36.   command[8]=(uint8_t)(crc & 0x00ff);
  37.   for (uint8_t a=0; a<10; a++) mySerial.write(command[a]);
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement