欢迎光临散文网 会员登陆 & 注册

用Arduino实现双声道和弦播放马里奥地下

2022-01-16 11:20 作者:你竟然打我-_-  | 我要投稿

这次的播放对象是马里奥兄弟地下城音乐

MIDI是这个样子的,同时两个音调和弦

遗憾的是,Arduino自带的tone函数同一时间只支持一个引脚输出,同时运行两个tone只执行一个命令,因为用的单一定时器。解决办法还是有的,安装Tone库,库的名字就叫Tone。详见https://github.com/bhagman/Tone

这个库非常好,

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)

意思就是说我的nano最多可以三声道和弦,接下来就开干吧,上代码:

pitches.h

主程序MarioUnderworld


用Arduino实现双声道和弦播放马里奥地下的评论 (共 条)

分享到微博请遵守国家法律