Skip to content

Commit 23bc243

Browse files
authored
es refactor
1 parent 337ebd4 commit 23bc243

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ function setup() {
1818
createCanvas(400, 400);
1919
noStroke();
2020
fill('#ff00aa22');
21+
receiveSensorData(handleData);
2122
}
2223

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);
24+
function handleData(data) {
2725

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);
26+
console.log(data); // output the values to log
27+
// data[0] is the 1st value, data[1] 2nd, etc.
3328

34-
});
29+
// draw stuff! Browse http://p5js.org/reference/
30+
background('#ddd');
31+
ellipse(200, 200, data[0]+10, data[0]+10);
32+
33+
}

0 commit comments

Comments
 (0)