int melody[]={5,3,3,4,2,2,1,2,3,4,5,5,5,5,3,3,4,2,2,1,3,5,5,3,2,2,2,2,2,3,4,3,3,3,3,3,4,5,5,3,3,4,2,2,1,3,5,5,1};
//節拍(小蜜蜂)
int beat[]={1,1,2,1,1,2,1,1,1,1,1,1,2,1,1,2,1,1,2,1,1,1,1,4,1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,2,1,1,2,1,1,1,1,4};
void setup(){
pinMode(buzzer,OUTPUT);
}
void loop(){
for(int i=0; i<49; i++){
tone(buzzer, freq[melody[i]-1]);
delay(beat[i]*320);
noTone(buzzer);
}
delay(1000);
}
複製代碼
作者: 尤爾呈 時間: 2022-2-8 19:47
本帖最後由 尤爾呈 於 2022-2-8 20:10 編輯
int buzzer=8;
// C D E F G A B
//音階頻率 Do Re Mi Fa So La Si
//int freq[]={262,294,330,349,392,440,494};
int freq[]={523,587,659,698,784,880,988};
//int freq[]={1046,1175,1318,1397,1568,1760,1976};
//歌曲音調(佩佩豬)
int melody[]={1,2,3,1, 1,2,3,1, 3,4,5, 3,4,5, 5,6,5,4,3,1,5,6,5,4,3,1, 1,5,1, 1,5};
//節拍(佩佩豬)
int beat[]={2,2,2,2,2,2,2,2,2,2,4,2,2,4,1,1,1,1,2,2,1,1,1,1,2,2,2,2,4,2,2,4};