何か曲を作ってみようと考え、「かえるのうた」を作りました。
なぜ「かえるのうた」にしたかというと、シャープやフラットを使わない音で構成され、テンポが変わる曲 ということが理由でした。
改めて考えると、「かえるのうた」は合唱の代表曲です。そこで合唱のような音の作成にチャレンジしました。合唱しているように聞こえるとよいのですが。
ついでに指揮も付けてみました。
下準備
① obnizスターターキットの用意
obnizの端子にパーツを接続
マトリックスLED:
MatrixLED_MAX7219 を使う場合は clk:0, cs:1, din:2, gnd:3, vcc:4
Keyestudio_HT16K33 を使う場合は gnd:0, vcc:1, sda:2, scl:3
サーボ:gnd:6,vcc:7,signal:8
ブザー:signal:9, vcc:10, gnd:11
② Visual Studio Codeの用意
初期設定
npm init -y
npm i axios
obnizとの連携の設定
npm install obniz
npm install canvas
これらをVisual Studio Codeのターミナルに入力しEnterを押してインストール
しておく。
実行
Visual Studio Codeに、以下のコードを入力。
var Obniz = require("obniz");
var obniz = new Obniz("xxxx-xxxx"); //自分のobnizIDを入れる。
obniz.onconnect = async function () {
const matrix = obniz.wired("MatrixLED_MAX7219", { clk:0, cs:1, din:2, gnd:3, vcc:4});
//Keyestudio_HT16K33の場合は
//const matrix = obniz.wired("Keyestudio_HT16K33", { gnd:0, vcc:1, sda:2, scl:3 });
matrix.init(8*1, 8); //Keyestudio_HT16K33の場合は要らない。
var servo = obniz.wired("ServoMotor", {gnd:6,vcc:7,signal:8});
var speaker = obniz.wired("Keyestudio_Buzzer", {signal:9, vcc:10, gnd:11});
matrix.brightness(7);
const ctx = obniz.util.createCanvasContext(matrix.width, matrix.height);
await obniz.wait(1000);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('カ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('エ', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ル', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('の', 0, 7);
matrix.draw(ctx);
servo.angle(0.0);
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('う', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('た', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('が', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
servo.angle(0.0);
await obniz.wait(600);
ctx.fillStyle = "black"; //ここから合唱始まり
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('き', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(30);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('こ', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(30);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('え', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(195.998) // 195.998 Hz;「ソ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(195.998) // 195.998 Hz;「ソ」
await obniz.wait(30);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('て', 0, 7);
matrix.draw(ctx);
servo.angle(0.0);
speaker.play(220.000) // 220.000 Hz;「ラ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(220.000) // 220.000 Hz;「ラ」
await obniz.wait(30);
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('く', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(195.998) // 195.998 Hz;「ソ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(195.998) // 195.998 Hz;「ソ」
await obniz.wait(30);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('る', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(30);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ヨ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(30);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
servo.angle(0.0);
await obniz.wait(600);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
speaker.play(174.614) // 174.614 Hz;「ファ」
servo.angle(120.0);
await obniz.wait(600);
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.play(195.998) // 195.998 Hz;「ソ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
speaker.play(220.000) // 220.000 Hz;「ラ」
servo.angle(0.0);
await obniz.wait(600);
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.play(195.998) // 195.998 Hz;「ソ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
speaker.play(174.614) // 174.614 Hz;「ファ」
servo.angle(120.0);
await obniz.wait(600);
speaker.stop();
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 5; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(50);
speaker.stop();
}
matrix.clear();
speaker.stop();
servo.angle(0.0);
await obniz.wait(600);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(60);
matrix.clear();
speaker.stop();
await obniz.wait(60);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(60);
speaker.stop();
matrix.clear();
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(150);
speaker.stop();
await obniz.wait(20);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(60);
matrix.clear();
speaker.stop();
await obniz.wait(60);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(60);
speaker.stop();
matrix.clear();
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(150);
speaker.stop();
await obniz.wait(20);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(60);
matrix.clear();
speaker.stop();
await obniz.wait(60);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(60);
speaker.stop();
matrix.clear();
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(150);
speaker.stop();
await obniz.wait(20);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(0.0);
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(60);
matrix.clear();
speaker.stop();
await obniz.wait(60);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(60);
speaker.stop();
matrix.clear();
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(150);
speaker.stop();
await obniz.wait(20);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(0);
for (let i = 0; i < 2; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(30);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.stop();
}
matrix.clear();
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(360);
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(20);
for (let i = 0; i < 2; i++) { // 繰り返す
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(30);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.stop();
}
matrix.clear();
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(360);
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(40);
for (let i = 0; i < 6; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
servo.angle(0.0);
speaker.stop();
await obniz.wait(300); //合唱ここまで
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ゲ', 0, 7);
matrix.draw(ctx);
servo.angle(0.0);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ロ', 0, 7);
matrix.draw(ctx);
for (let i = 0; i < 3; i++) { // 繰り返す
speaker.play(174.614) // 174.614 Hz;「ファ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(40);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(60.0);
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(40);
for (let i = 0; i < 4; i++) { // 繰り返す
speaker.play(164.814) // 164.814 Hz;「ミ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(320);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(120.0);
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(40);
for (let i = 0; i < 4; i++) { // 繰り返す
speaker.play(146.832) // 146.832 Hz;「レ」
await obniz.wait(30);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
speaker.stop();
await obniz.wait(320);
ctx.fillStyle = "black";
ctx.fillRect(0, 0, matrix.width, matrix.height);
ctx.fillStyle = "white";
ctx.font = "9px sans-serif";
ctx.fillText('ガ', 0, 7);
matrix.draw(ctx);
servo.angle(180.0);
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(80);
for (let i = 0; i < 12; i++) { // 繰り返す
speaker.play(130.813) // 130.813 Hz;「ド」
await obniz.wait(60);
speaker.stop();
await obniz.wait(10);
}
matrix.clear();
servo.angle(0.0);
speaker.stop();
}
工夫を要した箇所
①合唱の音を作るにあたり、繰り返しの機能を使用した時、繰り返し数が多い+早いと、
ブザーの音がかすれてしまう。またobnizが熱を持ち、曲の途中で遅延、またはフリーズ
することもあった。
音の様子とobnizの機能との兼ね合いを調整する必要があった。
②合唱の音を作成すると、無理やり2つの音を混在させているために音の揺らぎが出る。
これを逆に、かえるのガマ声と捉え、合唱でない単音部分も繰り返しの音にすること
により、より「カエル」らしき音に仕上がったと思う。
③合唱の音を作るにあたり、重なる曲同士の音の長さが違う場合、適宜調整を必要とした。
その他
端子を入れる場所を間違えてしまったことによるものなのか、スターターキットのマトリックスLED(Keyestudio_HT16K33)が壊れてしまった。マトリックスLED(MatrixLED_MAX7219)の3個セットを購入し使用したところ、またもや同じ原因で1つ壊れてしまった。扱いには注意が必要。