Music Box One—Key Version

来自Microduino Wikipedia
跳转至: 导航搜索
Language English

Objective

Here we build a music box. By a crash switch, you can play, pause and cut music.

Principle

Detect two touch switches' status to trigger music playing, pause and cut.

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-BM 1 Battery management
Microduino-Crash 2 Crash sensor
  • Other Equipment:
    • Two loudspeakers
    • One cell of battery

Preperation

  • Setup 1:Connect CoreUSB and PC/MAC with a USB cable, then open Arduino IDE.
  • Setup 2:

Download program examples: music_box

  • Setup 3:Open downloaded program, choose the right board and COM port , download program.

Software Debugging

Code description: Judge if the Crash's key is pressed for one part and send serial instructions to control Audio to play, pause and cut according to the status of the key for the other part.

  • " audio.h "controls Audio files and "key.h" detects files when the key is pressed.
  • The use of Audio serial port can be decided by jumper wires on the board. The default soft serial port is (2,3).
<source lang="cpp">
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

#define AUDIO_PORT mySerial   
//#define AUDIO_PORT mySerial

</source>

  • Key controls pin definition
int music1_Pin = 4;
int music2_Pin = 6;
  • Send serial instructions to control Audio's playing, pause or cut according to if the key is pressed.
  if (key_get(music1_Pin, 0))
  {
    delay(200);
    play_pause = !play_pause;
  }
  if (play_change != play_pause)
  {
    play_change = play_pause;
    if (play_pause)
      audio_play();
    else
      audio_pause();
  }
  if (key_get(music2_Pin, 0))
    audio_down();

Hardware Buildup

  • Setup1:Connect two Crash switches to D4 and D6 pins of Sensorhub.
  • Setup 2:Insert TF card into the slot of AudioShield.
MusicBox Joystick TF.jpg
  • Setup 3:Stack Audio and AuidoShield, connect them to PC and then you can save MP3 files into TF card's root directory.
MusicBox Joystick song.jpg
  • Setup4:Connect two loudspeakers to Amplifier.
MusicBox Joystick song speak.JPG
  • Setup5:Stack Audio, AudioShield and Amplifier. 将Audio,Audio shield,Amplifier
MusicBox Joystick 3 speak.JPG
  • Setup6:Connect the activated battery box and BM.
CoreUSB Ble steup2.jpg
  • Setup7:Stack all modules without fixed order (Except that Audio, AudioShield and Amplifier have to be together).

Result

Choosing to play, pause and cut songs via the crash switch. You can also build a beautiful shell for your project with LEGO since mCookie can be easily stacked with LEGO.

Video