Music Shield v2:PlayWithInput

Ardiuno Compatible shields

Moderator: cory.j.fowler

Music Shield v2:PlayWithInput

by Jacket Chen » Fri May 24, 2013 5:43 pm

You can input the the name of song from the SD Card,and the music shield can play the song you input.




#include <Fat16.h>
#include <Fat16Util.h>
#include <NewSPI.h>
#include <arduino.h>
#include <TimerOne.h>

#include "pins_config.h"
#include "vs10xx.h"
#include "newSDLib.h"
#include "MusicPlayer.h"
MusicPlayer myplayer;

char dtaSocket[10]; // the max leng of command
int dtaLen = 0; // actual leng of command
unsigned char getDta = 0;


void timerIsr()
{
if(Serial.available())
{
dtaSocket[dtaLen++] = Serial.read();
if(dtaSocket[dtaLen-1]=='\n')
{
playingState = PS_STOP;
getDta = 1;
}
if(dtaLen > 8)
{
getDta = 0;
dtaLen = 0;
}
}

}

void setup()
{
Serial.begin(9600);
myplayer.begin();//will initialize the hardware and set default mode to be normal.

Timer1.initialize(10000);
Timer1.attachInterrupt( timerIsr );
}

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
}

}
}
Attachments
libraries.rar
(85.74 KiB) Downloaded 328 times
Love little, love long.
User avatar
Junior-6
Junior-6
 
Posts: 665
Joined: Thu Jun 21, 2012 4:25 pm
Location: China

Re: Music Shield v2:PlayWithInput

by loovee » Tue May 28, 2013 4:09 pm

can i forks it in github?
User avatar
Elementary-3
Elementary-3
 
Posts: 353
Joined: Fri Nov 02, 2012 9:15 am

Re: Music Shield v2:PlayWithInput

by just_riko11 » Wed May 29, 2013 6:33 pm

Dear Jacky,

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.
Pre-kindergarten
Pre-kindergarten
 
Posts: 15
Joined: Mon May 20, 2013 2:10 pm

Re: Music Shield v2:PlayWithInput

by Jacket Chen » Thu May 30, 2013 9:29 am

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.
}
Love little, love long.
User avatar
Junior-6
Junior-6
 
Posts: 665
Joined: Thu Jun 21, 2012 4:25 pm
Location: China

Re: Music Shield v2:PlayWithInput

by just_riko11 » Thu May 30, 2013 2:54 pm

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);

String checksum;
boolean tagfound = false;

void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");

Serial1.begin(9600);
Serial.println("RFID Ready");
}

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.

Thanks
Pre-kindergarten
Pre-kindergarten
 
Posts: 15
Joined: Mon May 20, 2013 2:10 pm

Re: Music Shield v2:PlayWithInput

by Jacket Chen » Thu May 30, 2013 3:08 pm

So, this program you have tested without any errors and can work well ? We would have a try , it sounds more interesting.
Love little, love long.
User avatar
Junior-6
Junior-6
 
Posts: 665
Joined: Thu Jun 21, 2012 4:25 pm
Location: China

Re: Music Shield v2:PlayWithInput

by just_riko11 » Fri May 31, 2013 9:21 am

Yes it work,

could you help me to combine this code with MusicShield PlayWithInput where that tags found and then we call music from SD card?
:)
Pre-kindergarten
Pre-kindergarten
 
Posts: 15
Joined: Mon May 20, 2013 2:10 pm

Re: Music Shield v2:PlayWithInput

by tom.arroyo.iv » Tue Oct 29, 2013 9:39 am

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.
User avatar
Pre-kindergarten
Pre-kindergarten
 
Posts: 4
Joined: Mon Oct 07, 2013 12:37 pm

Re: Music Shield v2:PlayWithInput

by tom.arroyo.iv » Wed Oct 30, 2013 12:35 pm

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.
User avatar
Pre-kindergarten
Pre-kindergarten
 
Posts: 4
Joined: Mon Oct 07, 2013 12:37 pm

Re: Music Shield v2:PlayWithInput

by Jacket Chen » Thu Oct 31, 2013 7:43 pm

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"

if(judge(dtaSocket, "01",2) && tmp == 3) // input the name of a song,but the length need to be 5 bytes.
{
myplayer.playSong("01.mp3"); //play the song with the name you give.
}


or i wanna input "2" to play the music "02.mp3"

if(judge(dtaSocket, "2",1) && tmp == 2) // input the name of a song,but the length need to be 5 bytes.
{
myplayer.playSong("02"); //play the song with the name you give.
}


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.

Good luck.

Best Regards
Jacket
Love little, love long.
User avatar
Junior-6
Junior-6
 
Posts: 665
Joined: Thu Jun 21, 2012 4:25 pm
Location: China


Who is online
Users browsing this forum: No registered users and 1 guest