hi I need some help with a catalex mp3 controlled by arduino mega I would like to be able to input 2 digit numbers and play the corresponding song number and a potentiometer for volume control would help
thank you in advance
here is my code:
#include <SoftwareSerial.h>
#include <Keypad.h>
#define ARDUINO_RX 2//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 3//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);
static int8_t Send_buf[8] = {0} ;
#define CMD_SEL_DEV 0X09
#define DEV_TF 0X02
#define CMD_PLAY_W_VOL 0X22
#define CMD_PLAY 0X0D
#define CMD_PAUSE 0X0E
#define CMD_PREVIOUS 0X02
#define CMD_NEXT 0X01
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','4','7','*'},
{'2','5','8','0'},
{'3','6','9','#'},
{'A','B','C','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11, 10}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
delay(500);//Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
delay(200);//wait for 200ms
}
String str;
void loop() {
char key = kpd.getKey();
if(key=='1')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E01);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='2')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E02);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='3')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E03);//play the third track with volume 30 class
Serial.println("Third sound track.");
}
if(key=='4')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E04);//play the forth track with volume 30 class
Serial.println("Forth sound track.");
}
if(key=='5')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E05);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='6')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E06);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='7')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E07);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='8')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E08);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='9')
{
sendCommand(CMD_PLAY_W_VOL, 0X1E09);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(key=='B')
{
sendCommand(CMD_PAUSE, 0X0E);//pause the playing track
Serial.println("Pause");
}
if(key=='A')
{
sendCommand(CMD_PLAY, 0X0D);//play it again
Serial.println("Play");
}
if(key=='D')
{
sendCommand(CMD_PREVIOUS, 0X02);//play previous track
Serial.println("Playing previous track.");
}
if(key=='C')
{
sendCommand(CMD_NEXT, 0X01);//play next track
Serial.println("Playing next track.");
}
}
void sendCommand(int8_t command, int16_t dat)
{
delay(20);
Send_buf[0] = 0x7e; //starting byte
Send_buf[1] = 0xff; //version
Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
Send_buf[3] = command; //
Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
Send_buf[5] = (int8_t)(dat >> 8);//datah
Send_buf[6] = (int8_t)(dat); //datal
Send_buf[7] = 0xef; //ending byte
for(uint8_t i=0; i<8; i++)//
{
mySerial.write(Send_buf[i]) ;
}
}