Help us understand the problem. What is going on with this article?

Node.jsとArduinoで音量をモニタリング #nodebots #nodebots_jp

More than 1 year has passed since last update.

7/29はInternational NodeBots Dayということで、世界中でNodeBotsイベントが実施されています。

ということでJohnny-Fiveを触っています。

Grove Sound Sensor

Groveの音量センサーです。

サンプルコードを書くとArduino IDEでデータが確認できます。

Johnny-Fiveで値取得

これだけでいけます。今っぽいJohnny-Fiveコードですね。

app.js
'use strict';

const { Board, Sensor } = require('johnny-five');
const board = new Board();

board.on('ready', () => {
    const sensor = new Sensor(`A0`);
    sensor.on('change', (value) => console.log(value));
});

freeboardにつなげて可視化まで

Dweet.ioっていうデータをなげこめるサービスを使ってfreeboardにつなぎます。

0.8秒ごとにデータを投げてます。

app.js
'use strict';

const dweetClient = require("node-dweetio");
const dweetio = new dweetClient();
const { Board, Sensor } = require('johnny-five');
const board = new Board();
const THINGS_NAME = '任意のキー';

let sound = 0;

board.on('ready', () => {
    const sensor = new Sensor(`A0`);
    sensor.on('change', (value) => sound = value);
});

setInterval(() => {
    dweetio.dweet_for(THINGS_NAME, {sound: sound}, (err, dweet) => {
        if(err) {
            console.log(`err: ${err}`);
        }else{
            console.log(dweet);
        }
    });
}, 800);

所感

通信が発生しているので仕方ないけどもうすこしリアルタイムに連動できると楽しそうですね。

とはいえWebからサクッと確認できるのはさすがです。

https://freeboard.io/board/2qjddS

n0bisuke
プロトタイピング専門スクール「プロトアウトスタジオ」で教えたりしてます。 プロフ -> https://dotstud.io/members/n0bisuke
https://protoout.studio
dotstudio
全ての人がモノづくりを楽しむ世界を目指して活動しています。
https://dotstud.io
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした