Grove:スライドボリューム
Groveのスライドボリュームを接続し、Tibbo-Piのアナログ入力機能を使って、ボリュームの位置を数値として取得します。
(Groveデバイスの詳細は上記リンクから参照願います。)
Tibbitの配置
Tibbit #00-3 と Groveデバイスを接続したTPbit #02を挿入します。
ノードの配置
chを指定するために、changeノードを使用します。
以下のようにフローを配置します。
changeノードのプロパティを開き、アナログ値を取得したいchを指定するために、以下のように設定します。
Tibbit#00ノードの設定を開き、以下のようにスロットとIN_Analogを選択します。
injectノードは、以下のように「繰り返し」に「指定した時間間隔」を「0.5秒」と指定します。
Node-REDデプロイ後、定期的に値を取得することができます。
ボリューム左端で0、右端で255に近い値が取得できます。
※Tibbo-Piのアナログ入力機能は0~5Vを0~255の値として取得しますが、#00-3内部の回路の影響で、最大255ではなく250付近の値が取得されます。
サンプルフロー
1 |
[{"id":"b17ec143.e709e","type":"debug","z":"c2fa6897.58c3f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":280,"wires":[]},{"id":"211840bb.473d9","type":"inject","z":"c2fa6897.58c3f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":200,"wires":[["d4f60eab.c5af6"]]},{"id":"d4f60eab.c5af6","type":"change","z":"c2fa6897.58c3f8","name":"ch指定","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"A","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":200,"wires":[["abf8dfeb.78f78"]]},{"id":"abf8dfeb.78f78","type":"Tibbit-#00","z":"c2fa6897.58c3f8","name":"","tpSlot":"S01","communication":"GPIO","pinA":"IN_Analog","pinB":"other","pinC":"other","pinD":"other","i2cBaudRateK":"100","spiSpeed":"500","spiMode":"1","spiEndian":"1","serialConf":"","connectedStatus":"start","host":"","x":360,"y":240,"wires":[["b17ec143.e709e"]]}] |
LEDの点灯・消灯
取得した値により、Groveボード上のLEDを点灯・消灯します。ボリュームが大きすぎるときにLED点灯すると想定します。
値の閾値の判定のために、switchノードを使用します。
先程のフローに以下のようにswitchノードとそれ以降のノード(changeノードと#00ノード)を追加します。
switchノードのプロパティを開き、以下のように設定します。値が128より大きいとき、LEDをONする設定です。
2つのchangeノードはそれぞれ以下のように設定します。
追加したTibbit#00ノードは、以下のようにスロットとOUT(TTL出力)を選択します。
Node-REDデプロイ後、スライドを右側によせるとLEDが点灯し、左側によせると消灯します。
サンプルフロー
1 |
[{"id":"b17ec143.e709e","type":"debug","z":"c2fa6897.58c3f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":200,"wires":[]},{"id":"211840bb.473d9","type":"inject","z":"c2fa6897.58c3f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":200,"wires":[["d4f60eab.c5af6"]]},{"id":"d4f60eab.c5af6","type":"change","z":"c2fa6897.58c3f8","name":"ch指定","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"A","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":200,"wires":[["abf8dfeb.78f78"]]},{"id":"abf8dfeb.78f78","type":"Tibbit-#00","z":"c2fa6897.58c3f8","name":"","tpSlot":"S01","communication":"GPIO","pinA":"IN_Analog","pinB":"other","pinC":"other","pinD":"other","i2cBaudRateK":"100","spiSpeed":"500","spiMode":"1","spiEndian":"1","serialConf":"","connectedStatus":"start","host":"","x":340,"y":280,"wires":[["b17ec143.e709e","1b6de8ae.55bbc7"]]},{"id":"8d6ce145.43221","type":"Tibbit-#00","z":"c2fa6897.58c3f8","name":"","tpSlot":"S01","communication":"GPIO","pinA":"other","pinB":"OUT","pinC":"other","pinD":"other","i2cBaudRateK":"100","spiSpeed":"500","spiMode":"1","spiEndian":"1","serialConf":"","connectedStatus":"start","host":"","x":800,"y":360,"wires":[[]]},{"id":"5d3828f8.ffec28","type":"change","z":"c2fa6897.58c3f8","name":"ボリュームLED ON","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"B","tot":"str"},{"t":"set","p":"payload[0].v","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":340,"wires":[["8d6ce145.43221"]]},{"id":"8c56a77c.17f118","type":"change","z":"c2fa6897.58c3f8","name":"ボリュームLED OFF","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"B","tot":"str"},{"t":"set","p":"payload[0].v","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":380,"wires":[["8d6ce145.43221"]]},{"id":"1b6de8ae.55bbc7","type":"switch","z":"c2fa6897.58c3f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"128","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":360,"wires":[["5d3828f8.ffec28"],["8c56a77c.17f118"]]}] |