Skip to content

Commit ce612f7

Browse files
author
Lauren McCarthy
authored
Merge pull request #464 from jywarren/patch-2
Reformat + fix arduino sensor example
2 parents d829af9 + d801952 commit ce612f7

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

src/data/examples/en/10_Interaction/28_ArduinoSensor.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*
66
* https://github.com/publiclab/webjack
77
*
8-
* Note: WebJack library must be added to your index.html as
9-
* <script src="https://webjack.io/dist/webjack.js"></script>
8+
* Note: WebJack and p5-webjack libraries must be added to your index.html as follows:
9+
* <pre><code class="language-markup">&lt;script src="https://webjack.io/dist/webjack.js">&lt;/script></code></pre>
10+
* <pre><code class="language-markup">&lt;script src="https://jywarren.github.io/p5-webjack/lib.js">&lt;/script></code></pre>
11+
*
12+
* Working example: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
1013
*
1114
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
1215
* Load this sketch onto an Arduino:
@@ -18,17 +21,16 @@ function setup() {
1821
createCanvas(400, 400);
1922
noStroke();
2023
fill('#ff00aa22');
21-
}
24+
receiveSensorData(handleData);
25+
}
26+
27+
function handleData(data) {
2228

23-
// Set up the WebJack connection.
24-
// Use default profile: https://github.com/publiclab/webjack/blob/master/src/profiles.js
25-
let profile = WebJack.Profiles["SoftModem"];
26-
let connection = new WebJack.Connection(profile);
29+
console.log(data); // output the values to log
30+
// data[0] is the 1st value, data[1] 2nd, etc.
2731

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);
32+
// draw stuff! Browse http://p5js.org/reference/
33+
background('#ddd');
34+
ellipse(100, 200, data[0]+10, data[0]+10);
3335

34-
});
36+
}

src/data/examples/es/10_Interaction/28_ArduinoSensor.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*
66
* https://github.com/publiclab/webjack
77
*
8-
* Note: WebJack library must be added to your index.html as
9-
* <script src="https://webjack.io/dist/webjack.js"></script>
8+
* Note: WebJack and p5-webjack libraries must be added to your index.html as follows:
9+
* <pre><code class="language-markup">&lt;script src="https://webjack.io/dist/webjack.js">&lt;/script></code></pre>
10+
* <pre><code class="language-markup">&lt;script src="https://jywarren.github.io/p5-webjack/lib.js">&lt;/script></code></pre>
11+
*
12+
* Working example: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
1013
*
1114
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
1215
* Load this sketch onto an Arduino:
@@ -18,17 +21,16 @@ function setup() {
1821
createCanvas(400, 400);
1922
noStroke();
2023
fill('#ff00aa22');
24+
receiveSensorData(handleData);
2125
}
2226

23-
// Set up the WebJack connection.
24-
// Use default profile: https://github.com/publiclab/webjack/blob/master/src/profiles.js
25-
let profile = WebJack.Profiles["SoftModem"];
26-
let connection = new WebJack.Connection(profile);
27+
function handleData(data) {
28+
29+
console.log(data); // output the values to log
30+
// data[0] is the 1st value, data[1] 2nd, etc.
2731

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);
32+
// draw stuff! Browse http://p5js.org/reference/
33+
background('#ddd');
34+
ellipse(100, 200, data[0]+10, data[0]+10);
3335

34-
});
36+
}

src/data/examples/zh-Hans/10_Interaction/28_ArduinoSensor.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*
66
* https://github.com/publiclab/webjack
77
*
8-
* Note: WebJack library must be added to your index.html as
9-
* <script src="https://webjack.io/dist/webjack.js"></script>
8+
* Note: WebJack and p5-webjack libraries must be added to your index.html as follows:
9+
* <pre><code class="language-markup">&lt;script src="https://webjack.io/dist/webjack.js">&lt;/script></code></pre>
10+
* <pre><code class="language-markup">&lt;script src="https://jywarren.github.io/p5-webjack/lib.js">&lt;/script></code></pre>
11+
*
12+
* Working example: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
1013
*
1114
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
1215
* Load this sketch onto an Arduino:
@@ -18,17 +21,16 @@ function setup() {
1821
createCanvas(400, 400);
1922
noStroke();
2023
fill('#ff00aa22');
24+
receiveSensorData(handleData);
2125
}
2226

23-
// Set up the WebJack connection.
24-
// Use default profile: https://github.com/publiclab/webjack/blob/master/src/profiles.js
25-
let profile = WebJack.Profiles["SoftModem"];
26-
let connection = new WebJack.Connection(profile);
27+
function handleData(data) {
28+
29+
console.log(data); // output the values to log
30+
// data[0] is the 1st value, data[1] 2nd, etc.
2731

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);
32+
// draw stuff! Browse http://p5js.org/reference/
33+
background('#ddd');
34+
ellipse(100, 200, data[0]+10, data[0]+10);
3335

34-
});
36+
}

0 commit comments

Comments
 (0)