Arduino蜂鸣器《Viva La Vida》一小段旋律

在课上练习的时间里扒了一小段旋律,如果有人用得上请自取~

代码是从整个作业完整版中改过来的,删成这样不知道能不能正常运行,不过重点是谱面嘛……

#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); 
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值