Skip to content

Commit 9516d73

Browse files
author
Lauren McCarthy
committed
adding arduino example to website
1 parent 5d91c9e commit 9516d73

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @name Arduino sensor data via WebJack
3+
* @description WebJack is a way to read data from an Arduino (and other sources)
4+
* using audio -- it basically turns your Arduino into an audio modem.
5+
*
6+
* https://github.com/publiclab/webjack
7+
*
8+
* Note: WebJack library must be added to your index.html as
9+
* <script src="https://webjack.io/dist/webjack.js"></script>
10+
*
11+
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
12+
* Load this sketch onto an Arduino:
13+
* https://create.arduino.cc/editor/jywarren/023158d8-be51-4c78-99ff-36c63126b554/preview
14+
* Arduino will output audio from pin 3 + ground. Use microphone or an audio cable.
15+
*/
16+
17+
function setup() {
18+
createCanvas(400, 400);
19+
noStroke();
20+
fill('#ff00aa22');
21+
}
22+
23+
// Set up the WebJack connection.
24+
// Use default profile: https://github.com/publiclab/webjack/blob/master/src/profiles.js
25+
var profile = WebJack.Profiles["SoftModem"];
26+
var connection = new WebJack.Connection(profile);
27+
28+
// Runs every time a signal is 'heard'
29+
connection.listen(function(data) {
30+
31+
// Draw an ellipse at a height corresponding to the value received from the Arduino (sensor)
32+
ellipse(400/2, 400 - (data * 5), 20, 20);
33+
34+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @name Arduino sensor data via WebJack
3+
* @description WebJack is a way to read data from an Arduino (and other sources)
4+
* using audio -- it basically turns your Arduino into an audio modem.
5+
*
6+
* https://github.com/publiclab/webjack
7+
*
8+
* Note: WebJack library must be added to your index.html as
9+
* <script src="https://webjack.io/dist/webjack.js"></script>
10+
*
11+
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
12+
* Load this sketch onto an Arduino:
13+
* https://create.arduino.cc/editor/jywarren/023158d8-be51-4c78-99ff-36c63126b554/preview
14+
* Arduino will output audio from pin 3 + ground. Use microphone or an audio cable.
15+
*/
16+
17+
function setup() {
18+
createCanvas(400, 400);
19+
noStroke();
20+
fill('#ff00aa22');
21+
}
22+
23+
// Set up the WebJack connection.
24+
// Use default profile: https://github.com/publiclab/webjack/blob/master/src/profiles.js
25+
var profile = WebJack.Profiles["SoftModem"];
26+
var connection = new WebJack.Connection(profile);
27+
28+
// Runs every time a signal is 'heard'
29+
connection.listen(function(data) {
30+
31+
// Draw an ellipse at a height corresponding to the value received from the Arduino (sensor)
32+
ellipse(400/2, 400 - (data * 5), 20, 20);
33+
34+
});

0 commit comments

Comments
 (0)