该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#define NOTE_0 -1#define NOTE_A1 441
#define NOTE_A2 495
#define NOTE_A3 556
#define NOTE_A4 589
#define NOTE_A5 661
#define NOTE_A6 742
#define NOTE_A7 833#define NOTE_AL1 221
#define NOTE_AL2 248
#define NOTE_AL3 278
#define NOTE_AL4 294
#define NOTE_AL5 330
#define NOTE_AL6 371
#define NOTE_AL7 416#define NOTE_AH1 882
#define NOTE_AH2 990
#define NOTE_AH3 1112
#define NOTE_AH4 1178
#define NOTE_AH5 1322
#define NOTE_AH6 1484
#define NOTE_AH7 1665#define NOTE_E1 330
#define NOTE_E2 350#define NOTE_E3 393
#define NOTE_E4 441
#define NOTE_E5 495
#define NOTE_E6 556
#define NOTE_E7 624#define NOTE_EL1 165
#define NOTE_EL2 175
#define NOTE_EL3 196
#define NOTE_EL4 221
#define NOTE_EL5 248
#define NOTE_EL6 278
#define NOTE_EL7 312#define NOTE_EH1 661
#define NOTE_EH2 700
#define NOTE_EH3 786
#define NOTE_EH4 882
#define NOTE_EH5 990
#define NOTE_EH6 1112
#define NOTE_EH7 1248#define WHOLE 1
#define HALF 0.5
#define QUARTER 0.25
#define EIGHTH 0.25
#define SIXTEENTH 0.625
int t1[] =
{
NOTE_E1,NOTE_E2,NOTE_E3,NOTE_E1,
NOTE_E1,NOTE_E2,NOTE_E3,NOTE_E1,
NOTE_E3,NOTE_E4,NOTE_E5,
NOTE_E3,NOTE_E4,NOTE_E5,
NOTE_E5,NOTE_E6,NOTE_E5,NOTE_E4,NOTE_E3,NOTE_E1,
NOTE_E2,NOTE_EL5,NOTE_E1,NOTE_0
NOTE_E2,NOTE_EL5,NOTE_E1,NOTE_0
};
float d1[]=
{
0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,
0.5,0.5,1,
0.5,0.5,1,
0.5,0.5,0.5,0.5,1,1,
0.5,0.5,0.5,0.5,1,1,
1,1,1,1,
1,1,1,1,
};
int t2[]=
{
NOTE_AL5,NOT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);
length1=sizeof(t1)/sizeof(t1[0]);
length2=sizeof(t2)/sizeof(t2[0]);
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value == 0xF08F7) {//1
for(int x=0;x
{
newtone(tonepin,t1[x]);
delay(500*d1[x]);
noTone(tonepin);
}
delay(2000);
}
irrecv.resume();
}
if (irrecv.decode(&results)) {
if (results.value == 0xFD8877) {//2
for(int x=0;x
{
newtone(tonepin,t2[x]);
delay(500*d2[x]);
noTone(tonepin);
}
delay(2000);
}
irrecv.resume();
}
}void newtone(byte tonePin, int frequency, int duration) {
int period = 1000000L / frequency;
int pulse = period / 2;
for (long i = 0; i < duration * 1000L; i += period) {
digitalWrite(tonePin, HIGH);
delayMicroseconds(pulse);
digitalWrite(tonePin, LOW);
delayMicroseconds(pulse);
}
}