什么植物最老实| 打玻尿酸有什么副作用吗| 为什么记忆力很差| 钙片不能和什么一起吃| 鹅吃什么| 林俊杰属什么生肖| 什么什么分明的成语| 冰箱什么牌子好又省电质量又好| 培坤丸有什么作用功效| 中医为什么下午不把脉| 悬饮是什么意思| 力不从心什么意思| 儿童内热吃什么去内热| 生抽和老抽有什么区别| 胰腺炎吃什么中成药| 文房四宝是什么| 为什么阴道会放气| 熬夜有什么危害| 黑眼圈重是什么原因| 异卵双胞胎是什么意思| 小孩肚子痛挂什么科| 女孩断掌纹代表什么| 乔迁送什么水果| macd是什么意思| 山海经是什么| 常喝柠檬水有什么好处和坏处| 五液是指什么| 开业送什么礼物好| 1992年是什么年| 一月二十三号是什么星座| 查激素水平挂什么科| 女人梦见仇人代表什么| 什么的花纹| 清分日期是什么意思| 灰指甲长什么样子图片| 小叶增生是什么原因导致的| 预后是什么意思| 经常放屁是什么问题| 伏天吃羊肉有什么好处| 纯粹的人是什么性格| 犹太人割礼是什么意思| 白居易有什么之称| 什么是什么的摇篮| 嗓子痛吃什么消炎药| 火克什么| 高压正常低压低是什么原因| 纵是什么意思| 一花一世界一叶一菩提什么意思| 精油有什么作用| 喉咙有痰是什么原因| 饶舌是什么意思| 10a是什么意思| 一起共勉是什么意思| 晕车吃什么好| 花肠是母猪的什么部位| 甲油胶是什么| 牛和什么生肖最配| 舌苔发白是什么原因引起的| 大熊猫属于什么科| 梦到绿色的蛇是什么意思| 肌肉疼痛吃什么药| 抑郁症的表现是什么| 端庄是什么意思| 男才女貌是什么意思| 婴儿什么时候长牙| 桑树枝煮水有什么功效| 尿隐血阳性什么意思| 婴儿蚊虫叮咬红肿用什么药| 三月六日是什么星座| 梦到前女友是什么意思| 梅毒是什么病| 拉屎黑色的是什么原因| 总有眼屎是什么原因| 咳嗽吃什么药最好| 纱布是什么材质| 庹是什么意思| 轰20什么时候首飞| 梦见邻居是什么意思| 伊犁在新疆什么位置| 突然耳鸣是什么原因| 手机壳什么材质的好| 什么人适合吃红参| 梦见孩子拉粑粑是什么意思| 老是放屁什么原因| 矢量图是什么格式| 梦见和亲人吵架是什么意思| 牛骨煲什么汤对儿童好| 什么药可以当饭吃| 觊觎什么意思| 西米是什么东西| 发烧38度吃什么药| 田螺小子是什么意思| 大便拉水是什么原因| 不动产是什么意思| mews评分是什么意思| 梦见相亲是什么征兆| 兔子为什么不吃窝边草| 角膜炎用什么眼药水| 猪心炖什么治失眠| 舌尖有点麻是什么原因| 月经有点黑是什么原因| 带状疱疹后遗神经痛挂什么科| d二聚体是检查什么的| 一个火一个同念什么| 公共关系是什么意思| 小孩支气管炎吃什么药| 脸上长小疙瘩是什么原因| 贞洁是什么意思| 吃什么水果会变白| 哥伦比亚牌子什么档次| 左下腹痛挂什么科| 神经性皮炎用什么药膏效果最好| pt是什么元素| 驻村是什么意思| 检查梅毒挂什么科| 遐想的意思是什么| 梦见打老鼠是什么征兆| 宫颈轻糜是什么意思| 生僻字什么意思| 静脉曲张手术后吃什么| 九月三号是什么日子| 什么的松果| 仓鼠为什么吃自己的孩子| 化疗后吃什么补身体| 锲而不舍下一句是什么| 电瓶车什么牌子好| 7月16日什么星座| 脑梗会引起什么症状| 法令纹深是什么原因| 低密度脂蛋白偏高吃什么食物| 惊弓之鸟什么意思| 牙结石长什么样| 猫什么时候绝育| a2是什么材质| 热伤风吃什么药| giada是什么牌子| 吃什么可以增强抵抗力和免疫力| 什么情况下需要安装心脏起搏器| 九知道指的是什么| 胃炎吃什么药好| shark是什么牌子| 月球是地球的什么星| 免疫力低挂什么科| 95棉5氨纶是什么面料| 孙笑川是什么梗| 血氧低吃什么提高的快| 月经期吃什么水果| 肝经湿热吃什么中成药| 上焦有火吃什么中成药| 裸婚什么意思| 做脑ct挂什么科| 咖喱是什么东西| 喝栀子茶有什么好处| 梦见钓鱼是什么意思周公解梦| cdc是什么意思| 血管瘤是什么引起的| prp是什么| 女生纹身什么图案好看| 虚岁24岁属什么生肖| 苁蓉有什么功效| 丙肝是什么病严重吗| 嗓子不舒服吃什么水果| 歧途什么意思| 宫寒是什么引起的| 正觉是什么意思| 瘊子是什么| gi是什么| 青蛙属于什么类动物| 双肺纹理增粗是什么意思| 海为什么是蓝色的| 太古里是什么意思| 转注是什么意思| 单独玉米粉能做什么| 农历4月14日是什么星座| 暗渡陈仓什么意思| 阻滞是什么意思| 认知障碍是什么病| 生活防水是什么意思| 司马迁属什么生肖| 痛风不能吃什么食物| 昝是什么意思| 抑郁到什么程度要吃氟西汀| 日月同辉是什么意思| 喝茶对人体有什么好处| 2018 年是什么年| 怀孕吐得厉害吃什么可以缓解| act是什么| 退而求其次什么意思| 微波炉不热是什么原因| 上火吃什么可以降火| 世界什么| ra是什么病| 牙齿痛吃什么药好| 时柱将星是什么意思| 老打嗝是什么原因| 手心脚心发热吃什么药| 喝什么茶| 10月26是什么星座| 什么木材有香味| 鲍鱼吃什么| 氟哌噻吨美利曲辛片治什么病| 可怜巴巴是什么意思| 骨皮质断裂是什么意思| 人发胖的原因是什么引起的| 低密度脂蛋白高的原因是什么| 惴惴不安什么意思| 生气吃什么药可以顺气| 一九四九年属什么生肖| 乾隆是什么生肖| 绿色加什么颜色是蓝色| 什么是五险一金| 棠字五行属什么| handmade是什么牌子| 什么火没有烟| 布朗尼是什么| 旅游有什么好处| co是什么意思| 青海省会城市叫什么| 免疫力低下吃什么药| 喉咙痛是什么原因引起的| 易烊千玺属什么生肖| 眉毛里有痣代表什么| 四大皆空是什么生肖| 肺气肿是什么症状| 亲子鉴定需要什么样本| 吃百合有什么好处| 特务是什么| 心脾两虚吃什么中成药| 食管炎吃什么药最好| 守灵什么意思| 血压高吃什么水果好| 胃炎吃什么食物好得快| 牙龈出血吃什么药| kid什么意思| 肚子疼拉稀是什么原因| 赶尽杀绝什么意思| 百分比是什么意思| 吃什么最补胶原蛋白| 面瘫有什么症状| 什么茶能去体内湿气| 肝囊肿有什么症状表现| 梅五行属什么| 五官立体是什么意思| 热射病是什么| 大运流年是什么意思| ed是什么病| o型血容易得什么病| 尔昌尔炽什么意思| 瓠子和什么相克| 五花八门是指什么生肖| 什么人不怕冷| 毛周角化症是什么原因引起的| 存是什么生肖| 间断性是什么意思| 吃什么补镁| 双鱼座是什么象星座| 喝黑芝麻糊有什么好处| 梦见和别人结婚是什么意思| 五联什么时候打| 什么是低密度脂蛋白| 高血压是什么原因引起的| 手指发麻是什么原因引起的| 吃饭出汗多是什么原因| 医的笔顺是什么| 百度
Skip to content

Arduino library to play MML music using a piezo speaker on an output pin. Implemented using the MmlMusic base library.

Notifications You must be signed in to change notification settings

maxint-rd/MmlMusicPWM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

?

History

19 Commits
?
?
?
?
?
?
?
?
?
?
?
?

Repository files navigation

MmlMusicPWM

Arduino library to play MML music using a piezo speaker on an output pin. Implemented using the MmlMusic base library.

Introduction

MmlMusicPWM provides a means to play Music Macro Language sequences asynchronously. Where the Arduino tone() function allows for playing one single note, the MmlMusicPWM::play() method can play an entire music score.
It produces sound by means of a PWM signal on an output pin, which can be connected to a piezo speaker, or via an amplifier to a regular speaker. The music is played using a timer interrupt routine that changes the PWM frequency according the specific notes being played. This means we can do other things while the music keeps playing!

Device independant base class

This library is an extension to the MmlMusic base library. It is implemented as a child class of the device independant MmlMusic class. That class requires additional code via either a callback function or the implementation of a child class to implement the actual production of sound.

Support for different MCUs

This library supports playing MML music on different MCUs such as ESP8266, ATmega 328, 168 and ATtiny85. Depending on the MCU, it uses different timers and interrupts to produce the sound and to schedule playback of notes and silences. The music will keep on playing using a timer interrupt. On the ESP8266 the Ticker library is used. For ATmega 328/168 a Timer2 interrupt is used and a replacement method for tone() is provided. On the ATtiny85 resources are limited. There a Timer1 interrupt is used, which impacts regular PWM output.
BTW: The MmlMusic Tone example shows how to play notes without using a timer interrupt.

Installation/Usage

The library can be downloaded and installed as an Arduino library using the Sketch|Library menu. Just add the zipfile library and the enclosed examples should appear in the menu automatically.

Initialisation outside of Setup():

  // include header and initialize class
  #include <MmlMusicPWM.h>
  MmlMusicPWM music();

Then to play music, call the play method where you want:

music.play("T240 L16 O6 C D E F G");

When playing the rest of the sequence, the isPlaying() method can be used to determine if the sequence is still playing.

if(music.isPlaying()
{
    ...
}

Alterternatively a callback function can be used to signal the start or end of playing the tune. See the included examples for more detailed instructions on how to use this library.

Supported MML Syntax

Short syntax overview:

Command Description
? Tnnn Set tempo [32-255]. Examples: T120, T240
? Vnnn Set volume [0-128]. Note: limited effect on PWM-volume. Examples: V1, T120
? Lnn Set default note length [1-64]. Examples: L8, L16
? Mx ? Set timing. Mn=default, Ml=legato, Ms=staccato
? On ? Set octave [0-7]. Examples: O6, O7
? A-G? Play whole note. Example: C
? Ann-Gnn? Play note of alternative length [1-64]. Example: C4, A16
? Nnn Play frequency [0-96]. Example: N48
? ?# ? Play sharp note. Example: C#
? + ? Alternative for #
? ? ? Play flat note. Example: D-
?? R??? Rest. Example:? CDEC r CDEC
? P ? Alternative for R. Example: CDEC p CDEC
? . ? Longer note. Example: CDEC.?
? > shift octave up. Example: CDE>CDE.?
? ?< shift octave down.? Example: CDE<CDE.?
? ?, play multiple tracks? Example: CDE<CDE.,EDC<ECD.?

The supported MML-commands are a subset that may not completely cover all available music scores. If notes seem missing, check your score against the syntax above and replace unknown commands by equivalent supported alternatives. The music notation is case-insensitive. Spaces are not required but can be used for readability.

Features & limitations

  • Playing back multiple tracks is supported by the base library, but not (yet) by this library. Only a single pulse-stream is generated. The documentation of the comma-command above is maintained for future purposes.
  • This library was tested in the Arduino IDE v1.6.10 and v1.8.2. The current version of this library supports ESP8266, Atmel ATmega328 and ATmega168 MCUs. Support for ATtiny85 was also added, but since the ATtiny85 has limited resources, available memory limits it usage to simple applications. On ATtiny85 Timer1 is used, impacting the use of the regular PWM analogWrite() function.
  • There was a bug in the MmlMusic base library that could impact playback of notes and the duration of the delay() function. When ending the play-string with a number (eg. "T120 O4 G16"), the player could read beyond the end of the string, play whatever was next in memory and mess up the timer callback. This bug has been fixed. Please use the latest version of the MmlMusic base library. See this issue for details.
  • In ESP8266 cores 2.5.1 and higher reading a float array from PROGMEM had a byte alignment issue causing incorrect playback of notes. This issue was fixed in ESP8266 core 2.6.0 and has a workaround in the MmlMusic base library for earlier cores. See this issue for details.

Credits

The base library is based on the MusicEngine library by Chris Taylor, ported from mBed to Arduino. It is a follow-up of the ESP-MusicEngine library.

Links

Disclaimer

  • All code on this GitHub account, including this library is provided to you on an as-is basis without guarantees and with all liability dismissed. It may be used at your own risk. Unfortunately I have no means to provide support.

About

Arduino library to play MML music using a piezo speaker on an output pin. Implemented using the MmlMusic base library.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

晚上十点多是什么时辰 三高挂号挂什么科 79岁属什么 hr是什么 赵本山什么时候去世的
马粟是什么 吹空调感冒咳嗽吃什么药 奶油霜是什么 舌根白苔厚是什么原因 3475是什么罩杯
a4纸可以折什么 感冒为什么会发烧 高胆红素血症是什么病 ffa是什么意思 为什么饿的很快
孕中期头疼是什么原因 梦见别人家办丧事是什么意思 优生十项是检查什么 卧底大结局是什么 25度穿什么衣服
脚为什么会臭hcv9jop3ns9r.cn 男性尿血是什么原因导致的hcv8jop0ns2r.cn 骨科是什么梗jasonfriends.com 胰岛素是什么器官分泌的hcv7jop9ns2r.cn 双克是什么药hcv8jop0ns4r.cn
五金是什么hcv8jop0ns2r.cn 什么名字kuyehao.com 苑什么意思hcv9jop1ns2r.cn 长寿花什么时候开花fenrenren.com 6月12日什么星座hcv8jop8ns7r.cn
王安石是什么朝代的tiangongnft.com 七月二十八什么星座hcv9jop5ns9r.cn 身上有淤青是什么原因hcv8jop1ns5r.cn 103是什么意思xinjiangjialails.com 鸡口牛后是什么生肖hcv9jop5ns3r.cn
superman什么意思hcv7jop5ns4r.cn 备孕需要检查什么hcv9jop5ns8r.cn 鹅口疮是什么引起的hcv7jop4ns7r.cn 子宫憩室是什么hcv8jop5ns3r.cn 绝经一般在什么年龄hcv9jop0ns3r.cn
百度