Music Box Three—Infrared Control

From Microduino Wiki
Revision as of 14:40, 5 March 2016 by Admin (talk) (Equipment)
Jump to: navigation, search
Language: English  • 中文

Objective

Build a music box here! You can play music files in the TF card and change songs & volume with a remote controller or a Joystick.

MusicBox Remote.jpg

Principle

The principle is to detect if there is matched infrared remote control signal and play music according to different infrared signal. At the same time, it can detect and judge the Joystick's movement in the X-Y direction by reading the analog value. It'll choose the control mode according to the stay time.

MusicBox Remote-sch.jpg

Equipment

Module Number Function
mCookie-CoreUSB 1 Core board
mCookie-Hub 1 Sensor pin board
mCookie-Audio 1 Audio module
mCookie-Amplifier 1 Amplifier module
mCookie-OLED 1 OLED display
mCookie-BM 1 Battery management
Microduino-Joystick 1 Joystick sensor
Microduino-IR Receiver 1 Infrared receiver
  • Other Equipment:
    • Two loudspeakers
    • One battery
    • One TF card
    • One infrared remote controller
MusicBox Remote-module.jpg

Code

  • Setup 1:Connect the CoreUSB to the computer via a USB cable and open Arduino IDE.
CoreUSB Ble pc.jpg
  • Setup 2:Click Files > Examples > mCookie > _302_MusicBox_Remote and then load the program.
MusicBox Remote ino.jpg
  • Setup 3:Select the right board and COM port for program download. When it pops up "Done Uploading" notice, it means the program has been written into the CoreUSB module.
MusicBox Remote ino-ok.jpg

Software Debugging

  • Infrared Control
if (irrecv.decode(&results)) {
    //Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

    if (results.value == 0xFFA857)
    {
      music_status = !music_status;	//Play or pause 
      if (music_status == true)	//Play 
      {
        Serial.println("play");   //Serial outputs "PLAY"  
        audio_play();              //Audio starts to work.  
      }
      else	//Pause  
      {
        Serial.println("pause");   //Serial outputs "PAUSE"  
        audio_pause();              //Audio pauses. 
      }
    }
    else if (results.value == 0xFF906F)//Next song  
    {
      music_num++;	//Music number +
      if (music_num > music_num_MAX)	//Limit the number of songs if it is larger than 30.   
      {
        music_num = 1; //Music number returns to 1.  
      }
      music_status = true;
      audio_choose(music_num);
      audio_play();
      eeprom_WRITE();
    }
    else if (results.value == 0xFFE01F)//Last song  
    {
      music_num--;	//Music number reduces one.   
      if (music_num < 1)	// Limit the song number if it is less than one.
      {
        music_num = music_num_MAX;   //Maximum music number (Here is nine.)
      }
      music_status = true;
      audio_choose(music_num);       //Audio chooses music number. 

      audio_play();                  //Audio play 
      eeprom_WRITE();
    }
    else if (results.value == 0xFF02FD)//Volume+ 
    {
      music_vol++;                 //Volume+ 1
      if (music_vol > 30) music_vol = 1; //If the volume is more than 30, then it returns to 3.   
      audio_vol(music_vol);
      music_status = true;
      eeprom_WRITE();
    }
    else if (results.value == 0xFF9867)//Volume-  
    {
      music_vol--;                   // Volume-1    
      if (music_vol < 1) music_vol = 30; // If the volume is less than 1, then it returns to 30.
      audio_vol(music_vol);
      music_status = true;
      eeprom_WRITE();
    }
  }
  else
    results.value = 0;
  • Detect the joystick value
int uiStep()         //Change songs  
{
  if (analogRead(A0) < 100)  //Y-up
  {
    delay(50);       //50ms delay 
    if (analogRead(A0) < 100)      //
      return 1;      //Return to 1  
  }
  if (analogRead(A1) < 100)    //
  {
    delay(50);       //50ms delay   
    if (analogRead(A1) < 100)  //X-Right
      return 2;      //Return to 2  
  }
  if (analogRead(A1) > 900)    //X-Left
  {
    delay(50);       //50ms delay  
    if (analogRead(A1) > 900)  //
      return 3;      //Return to 3
  }
  return 0;
}
  • OLED display interface, which is available to be changed by users.
 //Main interface, which can be defined freely by users.  
void draw()
{
  setFont_L;

  u8g.setPrintPos(4, 16);
  u8g.print("Music_sta:");
  u8g.print(music_status ? "play" : "pause");

  u8g.setPrintPos(4, 16 * 2);
  u8g.print("Music_vol:");
  u8g.print(music_vol);
  u8g.print("/30");
  u8g.setPrintPos(4, 16 * 3);
  u8g.print("Music_num:");
  u8g.print(music_num);
  u8g.print("/");
  u8g.print(music_num_MAX);
  u8g.setPrintPos(4, 16 * 4);
  u8g.print("....Microduino....");
  //u8g.print(rtc.formatTime(RTCC_TIME_HMS));
}

Hardware Buildup

  • Setup 1:Use the wire to connect the OLED to the IIC interface of the Hub, then install the Joystick sensor to A0, A1 and the IR receiver sensor to D6.
MusicBox Remote hub.jpg
  • Setup 2:Insert the TF card into the slot of AudioShield.
MusicBox Joystick TF.jpg
  • Setup 3:Stack the Audio and AudioShield to the PC, and you can save MP3 files into the TF card. (Here we can save 9 to the most.)
MusicBox Joystick song.jpg
  • Setup4:Connect the two loudspeakers to the Amplifier.
MusicBox Joystick song speak.JPG
  • Setup5:Make sure you stack Audio, AudioShield and Amplifier together.
MusicBox Joystick 3 speak.JPG
  • Setup6:Connect the activated battery box with the BM module.
CoreUSB Ble steup2.jpg
  • Setup7:Stack all modules together without fixed order.(Except for Audio, AudioShield and Amplifier should be connected with each other). Congratulations! You just finished the circuit buildup!
MusicBox Remote steup ok.JPG

How to operate

You can push the corresponding button of the remote controller to change songs or volume.

MusicBox Remote ir.JPG

You can also control the music box with the Joystick, as follows:

MusicBox Joystick caozuo.JPG

Also you can choose DUO-V to be stacked with OLED so as to reduce the stacking height.

Result

To play, pause or change songs with an infrared remote controller of Joystick to control. Here you can also build a beautiful shell for your project with LEGO since mCookie can be easily stacked with LEGO boards.

MusicBox Remote ok.JPG

Video