/* 28//09/2021 * UARTSerialV3 * * Sounds with buttons * Serial MP3 Player A | Arduino UNO R3 RX | 3 TX | 4 VCC | 5V GND | GND Buttons on digital pins 8 & 9 */ #include "SoftwareSerial.h" #define ARDUINO_RX 4//should connect to TX of the Serial MP3 Player module #define ARDUINO_TX 3//connect to RX of the module SoftwareSerial myMP3(ARDUINO_RX, ARDUINO_TX); const int buttonOne = 8; const int buttonTwo = 9; unsigned long buttonDebounce; byte sendBuffer[6]; //buffer that will be used to store commands before sending //Manual says the code for this is 7E 03 35 01 EF so load into buffer array void selectTFCard(){ sendBuffer[0] = 0x7E; sendBuffer[1] = 0x03; sendBuffer[2] = 0x35; sendBuffer[3] = 0x01; sendBuffer[4] = 0xEF; sendUARTCommand(); } void playSound(byte songNumber){ sendBuffer[0] = 0x7E; sendBuffer[1] = 0x04; sendBuffer[2] = 0x41; sendBuffer[3] = 0x00; sendBuffer[4] = songNumber; sendBuffer[5] = 0xEF; sendUARTCommand(); } //play a sound at a set volume, only seems to apply to root directory files void playSoundAtVolume(byte volume,byte songNumber){ sendBuffer[0] = 0x7E; sendBuffer[1] = 0x04; sendBuffer[2] = 0x31; sendBuffer[3] = volume; sendBuffer[4] = songNumber; sendBuffer[5] = 0xEF; sendUARTCommand(); } // //set the playback volume 7E 03 31 0F EF = set volume to 0x0F = 15 void setplayVolume(byte volume){ sendBuffer[0] = 0x7E; sendBuffer[1] = 0x03; sendBuffer[2] = 0x31; sendBuffer[3] = volume; sendBuffer[4] = 0xEF; sendUARTCommand(); } //stop the current track playing void stopSound(){ sendBuffer[0] = 0x7E; sendBuffer[1] = 0x02; sendBuffer[2] = 0x0E; sendBuffer[3] = 0xEF; sendUARTCommand(); } void sendUARTCommand(){ int q; for(q=0;q buttonDebounce){ buttonPressed = digitalRead(buttonOne); if(buttonPressed > 0){ buttonDebounce = millis() + 200; stopSound();//stop any existing sounds playSoundAtVolume(15, 1);//play sound at volume 15, track 1...drill } } if(millis() > buttonDebounce){ buttonPressed = digitalRead(buttonTwo); if(buttonPressed > 0){ buttonDebounce = millis() + 200; stopSound();//stop any existing sounds playSoundAtVolume(25, 3);//play sound at volume 25, track 3...welder } } }