在课上练习的时间里扒了一小段旋律,如果有人用得上请自取~
代码是从整个作业完整版中改过来的,删成这样不知道能不能正常运行,不过重点是谱面嘛……
#define F4 349
#define G4 392
#define bA4 415
#define bB4 466
#define C5 523
#define bD5 554
#define bE5 622
#define F5 698
#define G5 784
const int buzzerPin = 10;
int tones[] = {F4,F5,F5,F5,bE5,F5,bE5,bB4,C5,bD5, bE5,bE5,bE5,C5,bE5,C5,F4,G4,bA4, F5,F5,F5,bE5,F5,bE5,bB4,C5,bD5,bD5, bE5,C5,bE5,bE5,C5,bE5,C5,F4,G4,bA4, F5,F5,F5,bE5,F5,G5,G5,G5,G5,F5, bE5,bE5,bE5,bD5,bE5,bD5,C5,C5,C5,C5, C5,bD5,bB4, bB4,bA4,G4,G4,C5,G4,bA4,G4,F4};
int beats[] = {250,500,500,250,250,250,750,250,500,750, 500,500,250,250,250,750,250,500,750, 500,500,250,250,250,750,250,500,500,250, 250,250,500,250,250,250,750,250,500,750, 500,500,250,250,250,500,500,250,750,250, 500,500,250,250,250,500,500,250,500,500, 1500,250,1750, 250,250,250,750,500,250,500,250,1250};
int length = sizeof(tones)/sizeof(tones[0]);
void setup() {
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
for(int i=0;i<length;i++){
tone(buzzerPin, tones[i]);
delay(beats[i]-125);
noTone(buzzerPin);
delay(125);
}
}