Playing Song Before Bed Machine
by janetwu20051119 in Circuits > Arduino
94 Views, 0 Favorites, 0 Comments
Playing Song Before Bed Machine
Intro:
The playing song before bed machine is a apparatus that plays simple song for you
And when the button is pressed, the apparatus is activated
The buzzer will play a simple Song while we pressed the bottom that is connected with the GND,7, and 2
People who accustomed listen song before bed can easily operating this machine since all you've got to do is pressing the button. Moreover, it brings a nice atmosphere, which to benefits people from sleeping well.
Step 1: Prepare Materials
Circuit:
- Arduino Leonardo
-Breadboard
-button
-buzzer
Step 2: Build Circuit
Build the circuit using the material as the Step 1 that shown
- The picture above is using Arduino Uno, but what I actually uses is Arduino Leonardo, whereas it's quite different but will not influences the result.
Step 3: Set Up the Code
#define NOTE_D0 -1
#define NOTE_D1 294 #define NOTE_D2 330 #define NOTE_D3 350 #define NOTE_D4 393 #define NOTE_D5 441 #define NOTE_D6 495 #define NOTE_D7 556
#define NOTE_DL1 147 #define NOTE_DL2 165 #define NOTE_DL3 175 #define NOTE_DL4 196 #define NOTE_DL5 221 #define NOTE_DL6 248 #define NOTE_DL7 278
#define NOTE_DH1 589 #define NOTE_DH2 661 #define NOTE_DH3 700 #define NOTE_DH4 786 #define NOTE_DH5 882 #define NOTE_DH6 990 #define NOTE_DH7 112
#define WHOLE 1 #define HALF 0.5 #define QUARTER 0.25 #define EIGHTH 0.25 #define SIXTEENTH 0.625
int tune[] = { NOTE_D0,NOTE_D0,NOTE_D0,NOTE_D6,NOTE_D7,NOTE_DH1,NOTE_D7,NOTE_DH1,NOTE_DH3,NOTE_D7,NOTE_D7,NOTE_D7,NOTE_D3,NOTE_D3, NOTE_D6,NOTE_D5,NOTE_D6,NOTE_DH1,NOTE_D5,NOTE_D5,NOTE_D5,NOTE_D3,NOTE_D4,NOTE_D3,NOTE_D4,NOTE_DH1, NOTE_D3,NOTE_D3,NOTE_D0,NOTE_DH1,NOTE_DH1,NOTE_DH1,NOTE_D7,NOTE_D4,NOTE_D4,NOTE_D7,NOTE_D7,NOTE_D7,NOTE_D0,N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分,用了一个序列定义为tune,整数
float duration[]=
{ 1,1,1,0.5,0.5, 1+0.5,0.5,1,1, 1,1,1,0.5,0.5, 1+0.5,0.5,1,1, 1,1,1,1, 1+0.5,0.5,1,1, 1,1,0.5,0.5,0.5,0.5, 1+0.5,0.5,1,1, 1,1,1,0.5,0.5, 1+0.5,0.5,1,1, 1,1,1,0.5,0.5, 1+0.5,0.5,1,1, 1,1,1,0.5,0.5, 1,0.5,0.25,0.25,0.25,0.5, 0.5,0.5,0.5,0.25,0.5,1, 0.5,0.5,0.5,0.5,1,1, 1,1,1,0.5,0.5, 1+0.5,0.5,1,1, 1,1,1,0.5,0.5, 1.5,0.5,1,1, 1,1,1,1, 0.5,0.5,1,1,0.5,0.5, 1.5,0.25,0.5,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 0.5,0.5,1,1,0.5,0.5, 1,0.5,0.5,1,1, 1,1,1,1, 1,1,1,1, 0.5,0.5,1,1,0.5,0.5, 1,0.5,0.25,0.5,1, 1,1,1,0.5,0.5 }
int length;//
int tonePin=5;//
void setup()
{ pinMode(tonePin,OUTPUT);//
length = sizeof(tune)/sizeof(tune[0]);//
}
void loop() { if (digitalRead( 2 )) {
for(int x=0;x
delay(400*duration[x]);//
noTone(tonePin);//
} delay(5000);//等待5秒后,循环重新开始 } }
citation:https://blog.csdn.net/u014751607/article/details/60318625
Step 4: Successfully Play the Song Before Going to Bed
Congrats to the product making, and sleep well!