Skip to content

Commit 4ceca23

Browse files
reconbotrwaldron
authored andcommitted
Examples: update light syntax
This updates the `light` examples to es6. I used eslint to do most of the work and manually removed binds and a few other things.
1 parent f5cd78c commit 4ceca23

15 files changed

+94
-94
lines changed

docs/grove-light-sensor-edison.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ node eg/grove-light-sensor-edison.js
2020

2121

2222
```javascript
23-
var five = require("johnny-five");
24-
var Edison = require("edison-io");
25-
var board = new five.Board({
23+
const five = require("johnny-five");
24+
const Edison = require("edison-io");
25+
const board = new five.Board({
2626
io: new Edison()
2727
});
2828

29-
board.on("ready", function() {
29+
board.on("ready", () => {
3030

3131
// Plug the Grove TSL2561 Light sensor module
3232
// into an I2C jack
33-
var light = new five.Light({
33+
const light = new five.Light({
3434
controller: "TSL2561"
3535
});
3636

docs/light-ambient-BH1750.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ node eg/light-ambient-BH1750.js
2929

3030

3131
```javascript
32-
var five = require("johnny-five");
33-
var board = new five.Board();
32+
const { Board, Light } = require("johnny-five");
33+
const board = new Board();
3434

35-
board.on("ready", function() {
36-
var light = new five.Light({
35+
board.on("ready", () => {
36+
const light = new Light({
3737
controller: "BH1750",
3838
});
3939

40-
light.on("data", function() {
41-
console.log("Lux: ", this.lux);
40+
light.on("data", (data) => {
41+
console.log("Lux: ", data.lux);
4242
});
4343
});
4444

docs/light-ambient-EVS_EV3.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ node eg/light-ambient-EVS_EV3.js
1818

1919

2020
```javascript
21-
var five = require("johnny-five");
22-
var board = new five.Board();
21+
const { Board, Light } = require("johnny-five");
22+
const board = new Board();
2323

24-
board.on("ready", function() {
25-
var light = new five.Light({
24+
board.on("ready", () => {
25+
const light = new Light({
2626
controller: "EVS_EV3",
2727
pin: "BAS1"
2828
});
2929

30-
light.on("change", function() {
31-
console.log("Ambient Light Level: ", this.level);
30+
light.on("change", (data) => {
31+
console.log("Ambient Light Level: ", data.level);
3232
});
3333
});
3434

docs/light-ambient-EVS_NXT.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ node eg/light-ambient-EVS_NXT.js
1818

1919

2020
```javascript
21-
var five = require("johnny-five");
22-
var board = new five.Board();
21+
const { Board, Light } = require("johnny-five");
22+
const board = new Board();
2323

24-
board.on("ready", function() {
25-
var light = new five.Light({
24+
board.on("ready", () => {
25+
const light = new Light({
2626
controller: "EVS_NXT",
2727
pin: "BAS2"
2828
});
2929

30-
light.on("change", function() {
31-
console.log("Ambient Light Level: ", this.level);
30+
light.on("change", (data) => {
31+
console.log("Ambient Light Level: ", data.level);
3232
});
3333
});
3434

docs/light-ambient-TSL2561.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ node eg/light-ambient-TSL2561.js
2929

3030

3131
```javascript
32-
var five = require("johnny-five");
33-
var board = new five.Board();
32+
const { Board, Light } = require("johnny-five");
33+
const board = new Board();
3434

35-
board.on("ready", function() {
36-
var light = new five.Light({
35+
board.on("ready", () => {
36+
const light = new Light({
3737
controller: "TSL2561",
3838
});
3939

40-
light.on("data", function() {
41-
console.log("Lux: ", this.lux);
40+
light.on("data", (data) => {
41+
console.log("Lux: ", data.lux);
4242
});
4343
});
4444

docs/light-reflected-EVS_EV3.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ node eg/light-reflected-EVS_EV3.js
1818

1919

2020
```javascript
21-
var five = require("johnny-five");
22-
var board = new five.Board();
21+
const { Board, Light } = require("johnny-five");
22+
const board = new Board();
2323

24-
board.on("ready", function() {
25-
var reflect = new five.Light({
24+
board.on("ready", () => {
25+
const reflect = new Light({
2626
controller: "EVS_EV3",
2727
pin: "BAS1",
2828
mode: "reflected"
2929
});
3030

31-
reflect.on("change", function() {
32-
console.log("Light Reflection Level: ", this.level);
31+
reflect.on("change", (data) => {
32+
console.log("Light Reflection Level: ", data.level);
3333
});
3434
});
3535

docs/light-reflected-EVS_NXT.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ node eg/light-reflected-EVS_NXT.js
1818

1919

2020
```javascript
21-
var five = require("johnny-five");
22-
var board = new five.Board();
21+
const { Board, Light } = require("johnny-five");
22+
const board = new Board();
2323

24-
board.on("ready", function() {
25-
var reflect = new five.Light({
24+
board.on("ready", () => {
25+
const reflect = new Light({
2626
controller: "EVS_NXT",
2727
pin: "BBS1",
2828
mode: "reflected"
2929
});
3030

31-
reflect.on("change", function() {
32-
console.log("Light Reflection Level: ", this.level);
31+
reflect.on("change", (data) => {
32+
console.log("Light Reflection Level: ", data.level);
3333
});
3434
});
3535

eg/arduino-starter-kit/light-theremin.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
var five = require("johnny-five");
2-
var Edison = require("edison-io");
3-
var board = new five.Board({
1+
const five = require("johnny-five");
2+
const Edison = require("edison-io");
3+
const board = new five.Board({
44
io: new Edison()
55
});
66

7-
board.on("ready", function() {
8-
var sensor = new five.Sensor({
7+
board.on("ready", () => {
8+
const sensor = new five.Sensor({
99
pin: "A0",
1010
freq: 30
1111
});
12-
var piezo = new five.Piezo(8);
13-
var min = 1024;
14-
var max = 0;
12+
const piezo = new five.Piezo(8);
13+
let min = 1024;
14+
let max = 0;
1515

16-
sensor.on("data", function() {
17-
min = Math.min(min, this.value);
18-
max = Math.max(max, this.value);
19-
var pitch = five.Fn.scale(this.value, min, max, 50, 4000);
16+
sensor.on("data", (data) => {
17+
min = Math.min(min, data.value);
18+
max = Math.max(max, data.value);
19+
const pitch = five.Fn.scale(data.value, min, max, 50, 4000);
2020
piezo.frequency(pitch, 20);
2121
console.log(min, max, pitch);
2222
});

eg/grove-light-sensor-edison.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
var five = require("../lib/johnny-five");
2-
var Edison = require("edison-io");
3-
var board = new five.Board({
1+
const five = require("../lib/johnny-five");
2+
const Edison = require("edison-io");
3+
const board = new five.Board({
44
io: new Edison()
55
});
66

7-
board.on("ready", function() {
7+
board.on("ready", () => {
88

99
// Plug the Grove TSL2561 Light sensor module
1010
// into an I2C jack
11-
var light = new five.Light({
11+
const light = new five.Light({
1212
controller: "TSL2561"
1313
});
1414

eg/light-ambient-BH1750.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const { Board, Light } = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
5-
var light = new five.Light({
4+
board.on("ready", () => {
5+
const light = new Light({
66
controller: "BH1750",
77
});
88

9-
light.on("data", function() {
10-
console.log("Lux: ", this.lux);
9+
light.on("data", (data) => {
10+
console.log("Lux: ", data.lux);
1111
});
1212
});

eg/light-ambient-EVS_EV3.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const { Board, Light } = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
5-
var light = new five.Light({
4+
board.on("ready", () => {
5+
const light = new Light({
66
controller: "EVS_EV3",
77
pin: "BAS1"
88
});
99

10-
light.on("change", function() {
11-
console.log("Ambient Light Level: ", this.level);
10+
light.on("change", (data) => {
11+
console.log("Ambient Light Level: ", data.level);
1212
});
1313
});

eg/light-ambient-EVS_NXT.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const { Board, Light } = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
5-
var light = new five.Light({
4+
board.on("ready", () => {
5+
const light = new Light({
66
controller: "EVS_NXT",
77
pin: "BAS2"
88
});
99

10-
light.on("change", function() {
11-
console.log("Ambient Light Level: ", this.level);
10+
light.on("change", (data) => {
11+
console.log("Ambient Light Level: ", data.level);
1212
});
1313
});

eg/light-ambient-TSL2561.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const { Board, Light } = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
5-
var light = new five.Light({
4+
board.on("ready", () => {
5+
const light = new Light({
66
controller: "TSL2561",
77
});
88

9-
light.on("data", function() {
10-
console.log("Lux: ", this.lux);
9+
light.on("data", (data) => {
10+
console.log("Lux: ", data.lux);
1111
});
1212
});

eg/light-reflected-EVS_EV3.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const { Board, Light } = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
5-
var reflect = new five.Light({
4+
board.on("ready", () => {
5+
const reflect = new Light({
66
controller: "EVS_EV3",
77
pin: "BAS1",
88
mode: "reflected"
99
});
1010

11-
reflect.on("change", function() {
12-
console.log("Light Reflection Level: ", this.level);
11+
reflect.on("change", (data) => {
12+
console.log("Light Reflection Level: ", data.level);
1313
});
1414
});

eg/light-reflected-EVS_NXT.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const { Board, Light } = require("../lib/johnny-five");
2+
const board = new Board();
33

4-
board.on("ready", function() {
5-
var reflect = new five.Light({
4+
board.on("ready", () => {
5+
const reflect = new Light({
66
controller: "EVS_NXT",
77
pin: "BBS1",
88
mode: "reflected"
99
});
1010

11-
reflect.on("change", function() {
12-
console.log("Light Reflection Level: ", this.level);
11+
reflect.on("change", (data) => {
12+
console.log("Light Reflection Level: ", data.level);
1313
});
1414
});

0 commit comments

Comments
 (0)