|

楼主 |
发表于 2022-5-5 16:48
|
显示全部楼层
程序十四:控制無源蜂鳴器發出兩隻老虎音調的聲音 (1)Arduino参考开源代码
- /*
- 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
- 程序十四:播放二只老虎乐曲
- */
- int buzzer=3; //設定蜂鳴器接腳為D3
- int duration = 500;
- int aSo = 392; //定义音符频率
- int bDo = 523;
- int bRe = 587;
- int bMi = 659;
- int bFa = 698;
- int bSo = 784;
- int bLa = 880;
- int bSi = 988;
- int bDDo = 1047;
- void setup(){
- pinMode(buzzer,OUTPUT); //設定蜂鳴器為輸出
- }
- void loop(){
- tone(3,bDo,duration);
- delay(600);
- tone(3,bRe,duration);
- delay(600);
- tone(3,bMi,duration);
- delay(600);
- tone(3,bDo,duration);
- delay(800);
-
- tone(3,bDo,duration);
- delay(600);
- tone(3,bRe,duration);
- delay(600);
- tone(3,bMi,duration);
- delay(600);
- tone(3,bDo,duration);
- delay(800);
-
- tone(3,bMi,duration);
- delay(600);
- tone(3,bFa,duration);
- delay(600);
- tone(3,bSo,duration);
- delay(800);
-
- tone(3,bMi,duration);
- delay(600);
- tone(3,bFa,duration);
- delay(600);
- tone(3,bSo,duration);
- delay(800);
- tone(3,bSo,duration);
- delay(600);
- tone(3,bLa,duration);
- delay(600);
- tone(3,bSo,duration);
- delay(600);
- tone(3,bFa,duration);
- delay(600);
- tone(3,bMi,duration);
- delay(700);
- tone(3,bDo,duration);
- delay(800);
- tone(3,bSo,duration);
- delay(600);
- tone(3,bLa,duration);
- delay(600);
- tone(3,bSo,duration);
- delay(600);
- tone(3,bFa,duration);
- delay(600);
- tone(3,bMi,duration);
- delay(700);
- tone(3,bDo,duration);
- delay(800);
- tone(3,bDo,duration);
- delay(700);
- tone(3,aSo,duration);
- delay(700);
- tone(3,bDo,duration);
- delay(800);
- tone(3,bDo,duration);
- delay(700);
- tone(3,aSo,duration);
- delay(700);
- tone(3,bDo,duration);
- delay(800);
- delay(2000);
- }
复制代码
|
|