Skip to content

Commit 687d032

Browse files
committed
Examples: miscellaneous nitpicks
1 parent 4ceca23 commit 687d032

11 files changed

+37
-37
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
const five = require("johnny-five");
1+
const {Board, Fn, Sensor, Piezo} = require("../lib/johnny-five.js");
22
const Edison = require("edison-io");
3-
const board = new five.Board({
3+
const board = new Board({
44
io: new Edison()
55
});
66

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

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);
16+
sensor.on("data", () => {
17+
min = Math.min(min, sensor.value);
18+
max = Math.max(max, sensor.value);
19+
const pitch = Fn.scale(sensor.value, min, max, 50, 4000);
2020
piezo.frequency(pitch, 20);
2121
console.log(min, max, pitch);
2222
});

eg/esc-bidirectional-forward-reverse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ board.on("ready", () => {
1111
const throttle = new Sensor("A0");
1212
const brake = new Button(4);
1313

14-
brake.on("press", esc.brake);
14+
brake.on("press", () => esc.brake());
1515

1616
throttle.scale(0, 100).on("change", () => {
1717
// 2 Seconds for arming.

eg/esc-bidirectional.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ board.on("ready", () => {
99
const throttle = new Sensor("A0");
1010
const brake = new Button(4);
1111

12-
brake.on("press", esc.brake);
12+
brake.on("press", () => esc.brake());
1313

1414
throttle.on("change", () => {
1515
esc.throttle(throttle.scaleTo(esc.pwmRange));

eg/esc-dualshock.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { Board, ESC, Fn } = require("../lib/johnny-five.js");
22
const dualShock = require("dualshock-controller");
33

44
const board = new Board();
5-
const controller = dualShock({
5+
const gamepad = dualShock({
66
config: "dualShock3",
77
analogStickSmoothing: false
88
});
@@ -12,11 +12,11 @@ board.on("ready", () => {
1212
let speed = 0;
1313
let last = null;
1414

15-
controller.on("connected", () => {
16-
controller.isConnected = true;
15+
gamepad.on("connected", () => {
16+
gamepad.isConnected = true;
1717
});
1818

19-
controller.on("dpadUp:press", () => {
19+
gamepad.on("dpadUp:press", () => {
2020
if (last !== "up") {
2121
speed = 0;
2222
} else {
@@ -26,7 +26,7 @@ board.on("ready", () => {
2626
last = "up";
2727
});
2828

29-
controller.on("dpadDown:press", () => {
29+
gamepad.on("dpadDown:press", () => {
3030
if (last !== "down") {
3131
speed = 0;
3232
} else {
@@ -36,13 +36,13 @@ board.on("ready", () => {
3636
last = "down";
3737
});
3838

39-
controller.on("circle:press", () => {
39+
gamepad.on("circle:press", () => {
4040
last = null;
4141
speed = 0;
4242
esc.brake();
4343
});
4444

45-
controller.on("right:move", position => {
45+
gamepad.on("right:move", position => {
4646
const y = Fn.scale(position.y, 255, 0, 0, 180) | 0;
4747

4848
if (y > 100) {

eg/led-array.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const {Board, Leds} = require("../lib/johnny-five.js");
22
const board = new Board();
33

44
board.on("ready", () => {
5-
const array = new Leds([3, 5, 6]);
5+
const leds = new Leds([3, 5, 6]);
66

7-
array.pulse();
7+
leds.pulse();
88
});
99
/* @markdown
1010

eg/led-fade-animation.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ board.on("ready", () => {
1515
});
1616

1717
// Toggle the led after 2 seconds (shown in ms)
18-
board.wait(2000, () => {
19-
led.fadeOut();
20-
});
18+
board.wait(2000, () => led.fadeOut());
2119
});

eg/motobot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ board.on("ready", () => {
3737
motors.b.rev(speed * 0.75);
3838
}
3939

40-
commands = [].slice.call(arguments);
40+
commands = Array.from(arguments);
4141
} else {
4242
if (ch >= 1 && ch <= 9) {
4343
speed = Fn.scale(ch, 1, 9, 0, 255);
44-
controller.apply(null, commands);
44+
controller(...commands);
4545
}
4646
}
4747
}

eg/motor-hbridge-dual.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
const {Board, Motors} = require("../lib/johnny-five.js");
99
const board = new Board();
10+
const invertPWM = true;
1011

1112
board.on("ready", () => {
1213
/**
1314
* Motor A: PWM 11, dir 12
1415
* Motor B: PWM 5, dir 4
1516
*/
1617
const motors = new Motors([
17-
{ pins: { dir: 12, pwm: 11 }, invertPWM: true },
18-
{ pins: { dir: 4, pwm: 5}, invertPWM: true }
18+
{ pins: { dir: 12, pwm: 11 }, invertPWM },
19+
{ pins: { dir: 4, pwm: 5}, invertPWM }
1920
]);
2021

2122
board.repl.inject({

eg/motor-sparkfun-edison-hbridge.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {Board, Motor} = require("../lib/johnny-five.js");
2-
var Edison = require("galileo-io");
2+
const Edison = require("galileo-io");
33
const board = new Board({
44
io: new Edison()
55
});

eg/motor-vnh5019.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const {Board, Motor} = require("../lib/johnny-five.js");
22
const board = new Board();
33

44
board.on("ready", () => {
5-
5+
66
// You can configure with explicit pins settings
77
const m1 = new Motor({
88
pins: {
@@ -25,17 +25,17 @@ board.on("ready", () => {
2525
});
2626

2727
// "start" events fire when the motor is started.
28-
[m1, m2].forEach( (motor, index) => {
28+
[m1, m2].forEach((motor, index) => {
2929
motor.on("start", () => {
30-
console.log("start motor " + (index+1));
30+
console.log(`start motor ${index+1}`);
3131

3232
// Demonstrate motor stop in 2 seconds
3333
this.wait(2000, motor.stop);
3434
});
3535
});
3636

3737
[m1, m2].forEach( motor => {
38-
38+
3939
// "stop" events fire when the motor is stopped.
4040
motor.on("stop", () => console.log("stop"));
4141
});

eg/motors-EVS_EV3.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
1+
const {Board, Motors} = require("../lib/johnny-five.js");
2+
const board = new Board();
3+
const controller = "EVS_EV3";
34

4-
board.on("ready", function() {
5-
var motors = new five.Motors([{
6-
controller: "EVS_EV3",
5+
board.on("ready", () => {
6+
const motors = new Motors([{
7+
controller,
78
pin: "BAM1"
89
}, {
9-
controller: "EVS_EV3",
10+
controller,
1011
pin: "BBM1"
1112
}, ]);
1213

0 commit comments

Comments
 (0)