arduino蜂鸣器两只老虎歌曲代码
时间: 2023-09-01 17:11:21 浏览: 244
两只老虎_两只老虎_cc936mycc936_蜂鸣器_stm32歌曲_STM32两只老虎_源码
5星 · 资源好评率100%
好的,以下是用Arduino控制蜂鸣器演奏《两只老虎》的代码:
```C++
int melody[] = {
NOTE_C4, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4,
NOTE_G4, 0, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4,
NOTE_D4, NOTE_D4, NOTE_C4, 0, 0, 0
};
int noteDuration[] = {
4, 4, 4, 4, 4, 4,
2, 4, 4, 4, 4, 4,
4, 4, 2, 4, 4, 4
};
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
for (int i = 0; i < 18; i++) {
int duration = 1000 / noteDuration[i];
tone(9, melody[i], duration);
int pauseBetweenNotes = duration * 1.30;
delay(pauseBetweenNotes);
noTone(9);
}
}
```
希望能帮到你!
阅读全文