用Arduino實(shí)現(xiàn)雙聲道和弦播放馬里奧地下
這次的播放對(duì)象是馬里奧兄弟地下城音樂(lè)

MIDI是這個(gè)樣子的,同時(shí)兩個(gè)音調(diào)和弦

遺憾的是,Arduino自帶的tone函數(shù)同一時(shí)間只支持一個(gè)引腳輸出,同時(shí)運(yùn)行兩個(gè)tone只執(zhí)行一個(gè)命令,因?yàn)橛玫膯我欢〞r(shí)器。解決辦法還是有的,安裝Tone庫(kù),庫(kù)的名字就叫Tone。詳見(jiàn)https://github.com/bhagman/Tone
這個(gè)庫(kù)非常好,
The library uses the hardware timers on the microcontroller to generate square-wave tones in the audible range.
You can output the tones on any pin (arbitrary). The number of tones that can be played simultaneously depends on the number of hardware timers (with CTC capability) available on the microcontroller.
ATmega8: 2 (timers 2, and 1)
ATmega168/328: 3 (timers 2, 1, and 0)
ATmega1280: 6 (timers 2, 3, 4, 5, 1, 0)
意思就是說(shuō)我的nano最多可以三聲道和弦,接下來(lái)就開(kāi)干吧,上代碼:
pitches.h
主程序MarioUnderworld