unsigned char judge(char *str1, char *str2, int n) //discriminant function
{
for(int i = 0; i<n; i++)
{
if(str1[i] != str2[i])
{
return 0;
}
}
return 1;
}
void loop()
{
myplayer.setPlayMode(MODE_NORMAL);
if(getDta)
{
getDta = 0;
int tmp = dtaLen;
dtaLen = 0;
if(judge(dtaSocket, "Name1",5) && tmp == 6) // input the name of a song,but the length need to be 5 bytes.
{
myplayer.playSong("Name1.mp3"); //play the song with the name you give.
}
else if(judge(dtaSocket, "Name2", 5) && tmp == 6) // input the name of a song,but the length need to be 5 bytes.
{
myplayer.playSong("Name2.mp3"); //play the song with the name you give.
}
else
{
Serial.println("unavailable command"); //only two command is available,others are not
}
}
In this source code, when that condition is true and then that process will be called. how we can stop that process when it that have another conditional value is true too?
example:
if( a == “1” ){
myplayer.playSong(“name1.mp3”);
}
else if (a==“2”){
myplayer.playSong(“name2.mp3”);
if a ==“1” we call that name1.mp3 , while that mp3 is running, that replaced where a==“2” and we must call other mp3.
Of course,if the mp3 of “1” is running, and then you input “2”, the previous song would be stoped,and mp3 of “2” start to play.
And if you want to use “1” to instead of “Name1”, you can:
if(judge(dtaSocket, “1”,1) && tmp == 2) // input the name of a song,but the length need to be 5 bytes.
{
myplayer.playSong(“Name1.mp3”); //play the song with the name you give.
}
else if(judge(dtaSocket, “2”, 1) && tmp == 2) // input the name of a song,but the length need to be 5 bytes.
{
myplayer.playSong(“Name2.mp3”); //play the song with the name you give.
}
i used that rfid tags for that instead.
my coding to read rfid tags :
uint8_t buffer[14];
uint8_t* buffer_at;
uint8_t* buffer_end = buffer + sizeof(buffer);
void loop()
{
if (Serial1.available()){
delay(20);
buffer_at = buffer;
while ( buffer_at < buffer_end )
{
*buffer_at++ = Serial1.read();
}
tagfound = true;
Serial1.end();
Serial1.begin(9600);
}
if (tagfound){
buffer_at = buffer;
uint32_t result = 0;
// Skip the preamble
++buffer_at;
// Accumulate the checksum, starting with the first value
uint8_t checksum = rfid_get_next();
// We are looking for 4 more values
int i = 4;
while(i--)
{
// Grab the next value
uint8_t value = rfid_get_next();
// Add it into the result
result <<= 8;
result |= value;
// Xor it into the checksum
checksum ^= value;
}
// Pull out the checksum from the data
uint8_t data_checksum = rfid_get_next();
// Print the result
Serial.print("Tag: ");
Serial.print(result);
if ( checksum == data_checksum )
Serial.println(" OK");
else
Serial.println(" CHECKSUM FAILED");
// We're done processing, so there is no current value
tagfound = false;
}
}
uint8_t rfid_get_next(void)
{
// sscanf needs a 2-byte space to put the result but we
// only need one byte.
uint16_t hexresult;
// Working space to assemble each byte
static char byte_chars[3];
// Pull out one byte from this position in the stream
snprintf(byte_chars,3,"%c%c",buffer_at[0],buffer_at[1]);
sscanf(byte_chars,"%x",&hexresult);
buffer_at += 2;
return static_cast<uint8_t>(hexresult);
}
So, when that tags number has detected by that antena that will be going to call that music. and if that other tags is true for another conditional that will stop that first process and call that next process.
SeeedStudio tech support has referred me to this thread stating that I should try this code for my Music Shield Ver.1.2. Is there anyone that can confirm if it will work?
I’ve tried Bill Porter’s library files & code, but the board continues to lock up.
Well, this code doesn’t work on v1.2 boards… After commenting out lines for sensors and other items that came up as faults I was able to get it to compile on IDE 1.0.5. When I opened up the IDE Serial Monitor all I saw on the screen was “ClockF:C000”. There was no response to anything that I typed into the serial monitor. Guess I’ll never get this board supported and I have a $30 paper weight.
Hi everyone,how are you? it’s a long time since the last time i posted here. I have heard that the previous demo can’t work well with Music Shield v1.2,maybe some notes you need to pay attention.
1 did your libraries of IDE include those libraries: Fat16,NewSPI,TimeOne,MusicPlayer_v1_7.
2 if you change the name of mp3 which you want to input,did you modify the program:for example,i wanna input “01” to play the music “01.mp3”
or i wanna input “2” to play the music “02.mp3”
3 i have input commands by IDE monitor,so the configuration is: Newline;9600 baud.
When you open the monitor,you can input a command after it displayed ClockF:C000.
Thank you for sharing the useful thing, I downloaded the phone sound as a free ringtone at: sonidosgratis.net did you try to download ringtones for your phone?