Arduino sensor data via WebJack / Arduino センサー

WebJackを使用してArduino(およびその他のソース)からデータを読み取る方法。基本的にArduinoをオーディオモデムに変えます。マイクまたはオーディオケーブルを使用します。

arduino serial sensor
Interaction Hardware

View Source Code

/*
 * @name Arduino sensor data via WebJack
 * @description WebJack is a way to read data from an Arduino (and other sources)
 * using audio -- it basically turns your Arduino into an audio modem.
 * 
 * <a href = "https://github.com/publiclab/webjack">https://github.com/publiclab/webjack</a>
 * 
 * Note: WebJack and p5-webjack libraries must be added to your index.html as follows:
 * <pre><code class="language-markup">&lt;script src="https://webjack.io/dist/webjack.js">&lt;/script></code></pre>
 * <pre><code class="language-markup">&lt;script src="https://jywarren.github.io/p5-webjack/lib.js">&lt;/script></code></pre>
 * 
 * Working example: <a href = "https://editor.p5js.org/jywarren/sketches/rkztwSt8M">https://editor.p5js.org/jywarren/sketches/rkztwSt8M</a>
 * 
 * Testing audio: <a href="https://www.youtube.com/watch?v=GtJW1Dlt3cg">https://www.youtube.com/watch?v=GtJW1Dlt3cg</a>
 * Load this sketch onto an Arduino: 
 * <a href="https://create.arduino.cc/editor/jywarren/023158d8-be51-4c78-99ff-36c63126b554/preview">https://create.arduino.cc/editor/jywarren/023158d8-be51-4c78-99ff-36c63126b554/preview</a>
 * Arduino will output audio from pin 3 + ground. Use microphone or an audio cable.
 */

function setup() { 
  // createCanvas(400, 400);
  createCanvas(windowWidth, windowHeight);
  noStroke();
  fill('#ff00aa22');
  receiveSensorData(handleData);
}

function handleData(data, connection) {

  console.log(data); // output the values to log
  // data[0] is the 1st value, data[1] 2nd, etc.

  // draw stuff! Browse http://p5js.org/reference/
  background('#ddd');
  ellipse(100, 200, data[0]+10, data[0]+10);

  // connection.send('send data back to the Arduino if its listening');
}

License

Source code is available on GitHub p5.js website legacy.

All examples are licensed under CC BY-NC-SA 4.0.