Music Box One—Key Version
Language | English |
---|
目录ObjectiveHere we build a music box. By a crash switch, you can play, pause and cut music. PrincipleDetect two touch switches' status to trigger music playing, pause and cut. Equipment
Preperation
Download program examples: music_box
Software DebuggingCode 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.
<source lang="cpp">
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define AUDIO_PORT mySerial
//#define AUDIO_PORT mySerial
</source>
int music1_Pin = 4;
int music2_Pin = 6;
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
ResultChoosing 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 |