Music Player

来自Microduino Wikipedia
Pkj讨论 | 贡献2014年6月9日 (一) 08:11的版本 (Created page with "{| style="width: 800px;" |- | ==Objective== The course will show you how to control Microduino modules to achieve a music player by using Processing. ==Equipment== *'''Mi...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

Objective

The course will show you how to control Microduino modules to achieve a music player by using Processing.

Equipment


  • Other Hardware Equipment
    • A USB cable
    • A loudspeaker
    • A storage card

Schematic

Just stack the four Microduino modules mentioned above and connect the two wires of the loudspeaker to Microduino-LM4863

Program

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/MicroduinoMusicplayer

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/ProcessingMusicplayer

Debugging

Step 1:The hardware building of the circuit can refer to: http://www.microduino.cc/wiki/index.php?title=Microduino_LM4863%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8-301KIT/zh


  • Insert the storage card into the slot of Microduino SD
301KIT-SD
  • Connect the loudspeaker
301KIT-Speak


Build the hardware environment according to the schematic, just like this:

ProcessingMusicplayerConnectionDiagram.jpg


Step 2:Audio Production

  • A SoX-based tool will be needed. And you can choose a proper conversion program according to the operational frequency of you Microduino modules.
  • Extract the file to “Microduino with 16 MHz” folder and put the audio file into the folder, then select “FullRate@16MHz_Mono.bat”
Audio
  • A dialog box will pop up, showing “Press any key to continue...”
Audio
  • After that, there appears a newly created folder and you will find the converted file inside. If failed, you can convert the audio file to “wav” format and have another try.
Audio
  • Copy the converted audio file to the storage card and insert the card into Microduino SD card slot.
  • Use IED to open the test program offered by Microduino and choose Microduino Core (Atmega328P@16M,5V). Here the things should be noticed before program download:
    • Since some libraries may have different pin definition, please download the changed libraries and replace the former ones;
    • The name of the audio file should also be changed to that of the generated audio file.

Step 3:Here the code needed:

The code of two ends (Processing and Microduino)

Microduino:

//The code keeps consistent with that of the 301kit of Microduino-LM4863 music player. The difference is the added function of receiving serial data

   if(Serial.available())
   {
     command=Serial.read();
     Serial.println(command);
     SdPlay.worker();
     if(num_two!=num_one)
     {
       num_two=num_one ;
       if(command=='p') {//’p’ means play
         SdPlay.play();
         Serial.println(F("Play."));
       }
       else if(command=='t') {//’t’ means stop
         SdPlay.pause();
         Serial.println(F("Pause."));
       }
       Serial.println(ok);
       Serial.print(num_one);
       Serial.println(num_two);
     }
   }

Processing:

//Get the data of the first serial port.

 println(Serial.list());
 // is always my Arduino, so I open Serial.list()[0].
 // Open whatever port is the one you're using.
 port = new Serial(this, Serial.list()[0], 9600);

//Add background-image, judge the mouse click, send play or pause instructions to Microduino to control the music player

 void draw() {
   image(bg, 0, 0);
   if (button) {
     image(play, x, y);
     port.write("p");
   } 
   else {
     image(pause, x, y);
     port.write("t");
   }
 }


Step 4:Download the code and get it compiled successfully.

Step 5:After the system goes well, a disk music player will appear on the screen. Click the button in the middle to see what happens.

Result

The music player starts or pauses along with the click of the button, just like this:.

ProcessingMusicplayerResult.jpg


Video