Music Box Three—Infrared Control
Language | English |
---|
目录ObjectiveBuild a music box here! You can play music files in the TF card and change songs & volume with a remote controller or a Joystick. PrincipleThe 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. Equipment
Code
Software Debugging
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;
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;
}
//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
How to operateYou can push the corresponding button of the remote controller to change songs or volume. You can also control the music box with the Joystick, as follows: Also you can choose DUO-V to be stacked with OLED so as to reduce the stacking height. ResultTo 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. Video |