1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

wemosでmml

Last updated at Posted at 2019-02-11

#概要

wemosでmml鳴らしてみた。

#配線

出力は、D9を、そのまま。
パソコン用スピーカーで鳴らす。

#写真

2019-02-11 08.51.13.jpg

#波形

gg.jpg

#利用したライブラリー

tiny mml parser

#サンプルコード

#include "mml.h"

const byte SND_OUT = 2;

MML mml;
MML_OPTION mmlopt;
char * text = "t110 l8 r4rcf4.ffedcd4.ccr>a<cd4dddfde>a2 r4a<cd4dfg4fef4edd4rcd4rddafg2. r4rcf4.ffedcd4.ccr>a<cd4dddfde>a2 r4a<cd4dfg4fef4edd4rcd4rddafg2.";

const int notes[] = {
	0, 9, 9, 10, 10, 11,  12, 12, 13, 14, 15, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 31,
	33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 93, 98, 104, 110, 117, 124,
	131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494,
	523, 554, 587, 622, 659, 699, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976,
	2093, 2218, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951,
	4186, 4435, 4699, 4978, 5274, 5587, 5920, 6272, 6645, 7040, 7459, 7902,
	8372, 8870, 9397, 9956, 10548, 11175, 11840, 12544
};

static void mml_callback(MML_INFO * p, void * extobj)
{
	switch (p->type)
	{
	case MML_TYPE_NOTE:
	{
		MML_ARGS_NOTE * args = &(p->args.note);
		snd(notes[args->number], args->ticks * 2);
	}
	break;
	case MML_TYPE_REST:
	{
		MML_ARGS_REST * args = &(p->args.rest);
		delay(args->ticks);
	}
	break;
	}
}
void snd(int hz, int ms)
{
	int len = ms / 4 * 3;
	tone(SND_OUT, hz, len);
	delay(ms);
}
void setup()
{
	Serial.begin(115200);
	mml_init(&mml, mml_callback, 0);
	MML_OPTION_INITIALIZER_DEFAULT(&mmlopt);
	Serial.println("start");
}
void loop()
{
	mml_setup(&mml, &mmlopt, text);
	while (mml_fetch(&mml) == MML_RESULT_OK);
}

#動画

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?