8
4

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 1 year has passed since last update.

熱帯夜に加山雄三の「海その愛」が流れるようにした

Last updated at Posted at 2022-11-01

寝れない夜のお供が欲しい

みなさんは暑がりですか?それとも寒がりですか?
私は極度の暑がりです。
夏は冷房がないと寝付くとこすら困難だ。

そんな暑くて寝れない夜に暑い歌を流して眠りの手助けをしてもらおう。

そこで選んだ曲が加山雄三さんの「海その愛」だ。

完成品

1分おきに気温を確認して音楽を流してくれる。

LINEの画面では
thumbnail_IMG_3064.png

Node-REDのフローで書き出したものが
image.png

初期設定

obniz.display.clear(); // 画面を消去
obnizParts.LM60 = obniz.wired("LM60",{ gnd: 0, output: 1, vcc: 2 }); // 温度センサー
obnizParts.Speaker = obniz.wired("Speaker",{ signal:10, gnd:11 });

JSONで書き出したものが

[{"id":"eb0090ab04ec1ed6","type":"obniz-function","z":"5d75aef43dac31d1","obniz":"015034b08e6aa6aa","name":"海その愛","code":"const sleep = (msec) => new Promise(res => setTimeout(res, msec));\n\nobniz.display.clear(); // 画面を消去\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(659); await sleep(400); obnizParts.Speaker.stop(); await sleep(1000); \n\"\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(880); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1174); await sleep(600); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();await sleep(1000);\n\"\"\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(659); await sleep(500); obnizParts.Speaker.stop(); await sleep(1000); \n\"\"\nobnizParts.Speaker.play(880); await sleep(300); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1174); await sleep(400); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();\n\"\"\n","x":560,"y":440,"wires":[["2033b7f633d9ca11"]]},{"id":"15a7c55c6dbf66fe","type":"obniz-repeat","z":"5d75aef43dac31d1","obniz":"","name":"1分おきにチェック","interval":"60000","code":"msg.payload = await obnizParts.LM60.getWait();\n\nreturn msg;","x":110,"y":320,"wires":[["27d1b6d28e674dd6","a927e6867924581c"]]},{"id":"e1fca52b2439e768","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":300,"wires":[]},{"id":"27d1b6d28e674dd6","type":"switch","z":"5d75aef43dac31d1","name":"気温別加山雄三","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"25","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"30","vt":"num","v2":"35","v2t":"num"},{"t":"gt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":320,"y":320,"wires":[["3c13c84537f2ec39"],["55c3ed6b48ad6c2b"],["73f1639a7f82433b"]]},{"id":"3c13c84537f2ec39","type":"function","z":"5d75aef43dac31d1","name":"人間、好きなことをやってる時って光るんだよね。","func":"msg.payload = msg.payload + '度超えてるな。人間、好きなことをやってる時って光るんだよね。'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":300,"wires":[["e1fca52b2439e768"]]},{"id":"55c3ed6b48ad6c2b","type":"function","z":"5d75aef43dac31d1","name":"自分の性格が、自分の運命を決めるんだ。","func":"msg.payload = msg.payload + \"度です。自分の性格が、自分の運命を決めるんだ。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":340,"wires":[["5110f06dd1a66882"]]},{"id":"73f1639a7f82433b","type":"function","z":"5d75aef43dac31d1","name":"人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。","func":"msg.payload = msg.payload + \"度です。人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["fc8af4b6faee882e"]]},{"id":"5110f06dd1a66882","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":340,"wires":[]},{"id":"fc8af4b6faee882e","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":380,"wires":[]},{"id":"a927e6867924581c","type":"switch","z":"5d75aef43dac31d1","name":"25度以上強制「海その愛」","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"25","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":440,"wires":[["eb0090ab04ec1ed6"]]},{"id":"2033b7f633d9ca11","type":"debug","z":"5d75aef43dac31d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":440,"wires":[]},{"id":"015034b08e6aa6aa","type":"obniz","obnizId":"","deviceType":"obnizboard","name":"","accessToken":"","code":"obniz.display.clear(); // 画面を消去\nobnizParts.LM60 = obniz.wired(\"LM60\",{ gnd: 0, output: 1, vcc: 2 }); // 温度センサー\nobnizParts.Speaker = obniz.wired(\"Speaker\",{ signal:10, gnd:11 });"}]

ユーザー環境・言語等

Node-RED v2.2.3
LINEBot
JavaScript

電子パーツ

Obniz Board 1Y
高精度IC温度センサ LM60BIZ
スピーカー

まずObnizに「海その愛」を流させる

Obnizから音楽を流すためには一音一音入力しないといけないという非常に地味な作業に入る。

まず楽譜の確保からだが、すべて有料であった。金は払いたくない。
そこで楽譜@ELISEのサンプルの合間を見ながら楽譜を完成させた。

しかし、楽譜が読めない。

そこで【楽譜が読めない人必見】楽譜の読み方をお教えします!音階と周波数の関係(平均律一覧表)の二つのサイトを駆使して、Obniz 1Y用のヘルツ楽譜を作り上げた。

この1フレーズを完成させるのだけでも一苦労。大変だから今回は「海よ俺の海よ~ 大きなその愛よ~」だけ流れることにする。

こんないい歌を1フレーズだけ流すのは逆に冒涜だった。

熱帯夜だけ流させる

安眠しているときには流れないようにしたいので、暑くて寝れない熱帯夜にだけ流れるように設定する。

そのためには高精度IC温度センサ LM60BIZを使って25度以上の時にだけ音楽が流れるようにNode-Redで設定する。

加山雄三風のlineからメッセージが来る

今回は気温別に合わせて加山雄三の格言3つが送られてくるようにする。

フローがこちら
image.png

JSONはこちら

[{"id":"e3dc16adc145302b","type":"PushMessage","z":"c82121acc2e0e415","name":"","x":1000,"y":400,"wires":[]},{"id":"dd7e2b4de0965d56","type":"switch","z":"c82121acc2e0e415","name":"気温別加山雄三","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"25","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"30","vt":"num","v2":"35","v2t":"num"},{"t":"gt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":180,"y":420,"wires":[["1af9dc9425e6e90f"],["a2f5013013e78156"],["9a21d0b5bbe8723d"]]},{"id":"1af9dc9425e6e90f","type":"function","z":"c82121acc2e0e415","name":"人間、好きなことをやってる時って光るんだよね。","func":"msg.payload = msg.payload + '度超えてるな。人間、好きなことをやってる時って光るんだよね。'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":400,"wires":[["e3dc16adc145302b"]]},{"id":"a2f5013013e78156","type":"function","z":"c82121acc2e0e415","name":"自分の性格が、自分の運命を決めるんだ。","func":"msg.payload = msg.payload + \"度です。自分の性格が、自分の運命を決めるんだ。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":440,"wires":[["40eb03b09258db8c"]]},{"id":"9a21d0b5bbe8723d","type":"function","z":"c82121acc2e0e415","name":"人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。","func":"msg.payload = msg.payload + \"度です。人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":480,"wires":[["afe0a3b8d5392ce4"]]},{"id":"40eb03b09258db8c","type":"PushMessage","z":"c82121acc2e0e415","name":"","x":1000,"y":440,"wires":[]},{"id":"afe0a3b8d5392ce4","type":"PushMessage","z":"c82121acc2e0e415","name":"","x":1000,"y":480,"wires":[]}]

最後にこれをObnizの処理と組み合わせる。
image.png

[{"id":"eb0090ab04ec1ed6","type":"obniz-function","z":"5d75aef43dac31d1","obniz":"015034b08e6aa6aa","name":"海その愛","code":"const sleep = (msec) => new Promise(res => setTimeout(res, msec));\n\nobniz.display.clear(); // 画面を消去\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(659); await sleep(400); obnizParts.Speaker.stop(); await sleep(1000); \n\"\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(880); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1174); await sleep(600); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();await sleep(1000);\n\"\"\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(659); await sleep(500); obnizParts.Speaker.stop(); await sleep(1000); \n\"\"\nobnizParts.Speaker.play(880); await sleep(300); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1174); await sleep(400); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();\n\"\"\n","x":560,"y":440,"wires":[["2033b7f633d9ca11"]]},{"id":"804ddd3a5970cc82","type":"debug","z":"5d75aef43dac31d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":240,"wires":[]},{"id":"17756f343dd5498a","type":"obniz-function","z":"5d75aef43dac31d1","obniz":"","name":"","code":"msg.payload = \"finish\";\nawait obniz.wait(1000); \nobniz.close();\n\nreturn msg;","x":520,"y":240,"wires":[["804ddd3a5970cc82"]]},{"id":"9f841fb91e320531","type":"inject","z":"5d75aef43dac31d1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":240,"wires":[["17756f343dd5498a"]]},{"id":"15a7c55c6dbf66fe","type":"obniz-repeat","z":"5d75aef43dac31d1","obniz":"","name":"1分おきにチェック","interval":"60000","code":"msg.payload = await obnizParts.LM60.getWait();\n\nreturn msg;","x":110,"y":320,"wires":[["27d1b6d28e674dd6","a927e6867924581c"]]},{"id":"e1fca52b2439e768","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":300,"wires":[]},{"id":"27d1b6d28e674dd6","type":"switch","z":"5d75aef43dac31d1","name":"気温別加山雄三","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"25","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"30","vt":"num","v2":"35","v2t":"num"},{"t":"gt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":320,"y":320,"wires":[["3c13c84537f2ec39"],["55c3ed6b48ad6c2b"],["73f1639a7f82433b"]]},{"id":"3c13c84537f2ec39","type":"function","z":"5d75aef43dac31d1","name":"人間、好きなことをやってる時って光るんだよね。","func":"msg.payload = msg.payload + '度超えてるな。人間、好きなことをやってる時って光るんだよね。'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":300,"wires":[["e1fca52b2439e768"]]},{"id":"55c3ed6b48ad6c2b","type":"function","z":"5d75aef43dac31d1","name":"自分の性格が、自分の運命を決めるんだ。","func":"msg.payload = msg.payload + \"度です。自分の性格が、自分の運命を決めるんだ。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":340,"wires":[["5110f06dd1a66882"]]},{"id":"73f1639a7f82433b","type":"function","z":"5d75aef43dac31d1","name":"人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。","func":"msg.payload = msg.payload + \"度です。人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["fc8af4b6faee882e"]]},{"id":"5110f06dd1a66882","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":340,"wires":[]},{"id":"fc8af4b6faee882e","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":380,"wires":[]},{"id":"a927e6867924581c","type":"switch","z":"5d75aef43dac31d1","name":"25度以上強制「海その愛」","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"25","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":440,"wires":[["eb0090ab04ec1ed6"]]},{"id":"2033b7f633d9ca11","type":"debug","z":"5d75aef43dac31d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":440,"wires":[]},{"id":"015034b08e6aa6aa","type":"obniz","obnizId":"","deviceType":"obnizboard","name":"","accessToken":"","code":"obniz.display.clear(); // 画面を消去\nobnizParts.LM60 = obniz.wired(\"LM60\",{ gnd: 0, output: 1, vcc: 2 }); // 温度センサー\nobnizParts.Speaker = obniz.wired(\"Speaker\",{ signal:10, gnd:11 });"}]

結論

余計寝れなくなった。1分おきに流れる音楽に気が狂いそうになる最悪の結果に。

当初の予定とは逆の結論に至ってしまった。出来たら意外と何とか実用できると思っていたが、その予想が外れることになるとは思わなかった。

8
4
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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?