LINEBot×obnizで、「赤鼻のトナカイ」「Joy to the world」が流れる仕組みを作ってみた！

###「素振りを頑張った君へ」最高のプレゼント！！
素振りの練習を頑張ったあなたへ最高のサプライズプレゼントを用意しました。
LINEから、「素振りの練習終わったよ！」と伝えると返信がきて、サプライズの音楽が流れるシステムを制作しました。

##開発環境
・[LINEBot公式アカウント解説](https://zenn.dev/protoout/articles/16-line-bot-setup)
・[Visual Studio Code基本操作](https://zenn.dev/protoout/articles/19-vscode-handson)
・[LINEBot参考ページ](https://qiita.com/n0bisuke/items/ceaa09ef8898bee8369d)
・[obniz公式ドキュメント（起動とWi-Fi設定）](https://obniz.com/ja/doc/reference/board-1y/quick-start/)
・[obniz公式ドキュメント（Speaker）](https://obniz.io/ja/sdk/parts/Speaker/README.md)

##制作物
<iframe width="560" height="315" src="https://www.youtube.com/embed/7PAOJR0NqmQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

#＃ソースコード「赤鼻のトナカイ」「Joy to the world」
<details><summary>ソースコード　<font color="Red">**(クリックで表示)**</font></summary><div><br><br>

```js
'use strict';
// obniz呼び出し
const Obniz = require('obniz');
const obniz = new Obniz("自分のID");  // Obniz_ID に自分のIDを入れます
​
const express = require('express');
const line = require('@line/bot-sdk');
const axios = require('axios');
const PORT = process.env.PORT || 3000;
​
const config = {
    channelAccessToken: '##########################',
    channelSecret: '###################'
};
​
const app = express();
​
app.post('/webhook', line.middleware(config), (req, res) => {
    console.log(req.body.events);
    Promise
      .all(req.body.events.map(handleEvent))
      .then((result) => res.json(result));
});
​
const client = new line.Client(config);
​
// obniz接続
obniz.onconnect = async function () {
​
var servo = obniz.wired("ServoMotor", {gnd:0, vcc:1, signal:2});
​
// LED　赤
var led = obniz.wired("LED", {anode:6, cathode:7});
led.blink(210); // 210msec
// LED　青
var led = obniz.wired("LED", {anode:8, cathode:9});
led.blink(210); // 210msec
// LED　黄
var led = obniz.wired("LED", {anode:10, cathode:11});
led.blink(210); // 210msec
​
let count = 0;
//　
let angles = [10, 50, 10, 50, 10, 180, 10, 50, 10, 50, 10, 180, 10, 50, 10, 50, 10, 50, 10, 50, 10, 180, 10, 50, 10, 50, 10, 50, 10, 50, 10, 50, 10, 180, 10, 50, 10, 180, 10];
let timer = setInterval(() => {
    count++;
    servo.angle(angles[count]);
    //
    if (count >= 100) {
     clearInterval(timer);
    let degrees = 300.0;
    }
}, 1200);//500msec
​
  obniz.display.clear();
  obniz.display.print("BestPractice Merry Christmas!");
}
​
function handleEvent(event) {
  if (event.type !== 'message' || event.message.type !== 'text') {
    return Promise.resolve(null);
  }
​
  let mes = ''
  if(event.message.text === '素振りの練習終わったよ！'){
    mes = 'よく頑張りました！頑張ったあなたへ最高のプレゼント!!!'; //待ってねってメッセージだけ先に処理
    getAskObnizSpeaker(event.source.userId); //スクレイピング処理が終わったらプッシュメッセージ
  }else{
    mes = event.message.text;
  }
​
  return client.replyMessage(event.replyToken, {
    type: 'text',
    text: mes
  });
}
​
const getAskObnizSpeaker = async (userId) => {
 // スピーカーを呼び出す
 const speaker = obniz.wired("Speaker", {signal:4, gnd:5});
 console.log("Speaker")
 await client.pushMessage(userId, {
  type: 'text',
  text: "プレゼントForYou!",
});
​
 // 音階とhzの参考サイト https://tomari.org/main/java/oto.html
 await speaker.play(391.995); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(600);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(1300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(1500);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(1600);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995);
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(200);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(400);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(1400);
 await speaker.stop();
 await obniz.wait(100);
​
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(261.626); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000);
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(493.883); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665);
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(261.626); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(523.251); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(440.000); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(391.995); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(349.228); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(329.628); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(293.665); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
 await speaker.play(261.626); 
 await obniz.wait(300);
 await speaker.stop();
 await obniz.wait(100);
​
}
app.listen(PORT);
console.log(`Server running at ${PORT}`);
```
</div></details>

##まとめ
音階もいちから制作したので、皆さんぜひ使ってみてくださいませ！！！
動画は、早送りしてますが、音楽は、ゆっくり流れます！！
クラッカーを最後鳴らすところまで制作したかったのですが、出来ませんでした！！
次への課題です！