xxxxxxxxxx
45
// WebJack is a way to read data from an Arduino using audio: it
// basically turns your Arduino into an audio modem. Docs at bottom.
// Test it even without an Arduino/sensor with this recorded audio:
// https://youtube.com/watch?v=GtJW1Dlt3cg
var connection;
function setup() {
createCanvas(800, 800);
noStroke();
fill('#ff00aa');
connection = 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('hello world'); // send data back...
}
function draw() {
// if (connection()) connection().send('hello world'); // send data back...
}
// https://webjack.io - test your audio setup and learn more!
//
// Use with https://publiclab.org/simple-air-sensor if it has a WebJack plug
//
// To use a sensor, load this sketch onto an Arduino:
// https://create.arduino.cc/editor/jywarren/023158d8-be51-4c78-99ff-36c63126b554/preview
// WebJack will output audio from pin 3 + ground. Use speaker + microphone, or an audio cable.
// Note: WebJack library has been added to index.html
//
// https://github.com/jywarren/p5js-webjack (docs)
//