From 687d0327ad950eca6131c3f62e1d340dcfe69308 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 21 Aug 2019 16:31:04 -0400 Subject: [PATCH] Examples: miscellaneous nitpicks --- eg/arduino-starter-kit/light-theremin.js | 16 ++++++++-------- eg/esc-bidirectional-forward-reverse.js | 2 +- eg/esc-bidirectional.js | 2 +- eg/esc-dualshock.js | 14 +++++++------- eg/led-array.js | 4 ++-- eg/led-fade-animation.js | 4 +--- eg/motobot.js | 4 ++-- eg/motor-hbridge-dual.js | 5 +++-- eg/motor-sparkfun-edison-hbridge.js | 2 +- eg/motor-vnh5019.js | 8 ++++---- eg/motors-EVS_EV3.js | 13 +++++++------ 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/eg/arduino-starter-kit/light-theremin.js b/eg/arduino-starter-kit/light-theremin.js index 1c5cbb749..578eec94e 100644 --- a/eg/arduino-starter-kit/light-theremin.js +++ b/eg/arduino-starter-kit/light-theremin.js @@ -1,22 +1,22 @@ -const five = require("johnny-five"); +const {Board, Fn, Sensor, Piezo} = require("../lib/johnny-five.js"); const Edison = require("edison-io"); -const board = new five.Board({ +const board = new Board({ io: new Edison() }); board.on("ready", () => { - const sensor = new five.Sensor({ + const sensor = new Sensor({ pin: "A0", freq: 30 }); - const piezo = new five.Piezo(8); + const piezo = new Piezo(8); let min = 1024; let max = 0; - sensor.on("data", (data) => { - min = Math.min(min, data.value); - max = Math.max(max, data.value); - const pitch = five.Fn.scale(data.value, min, max, 50, 4000); + sensor.on("data", () => { + min = Math.min(min, sensor.value); + max = Math.max(max, sensor.value); + const pitch = Fn.scale(sensor.value, min, max, 50, 4000); piezo.frequency(pitch, 20); console.log(min, max, pitch); }); diff --git a/eg/esc-bidirectional-forward-reverse.js b/eg/esc-bidirectional-forward-reverse.js index e5ae01128..f4fbd6c34 100644 --- a/eg/esc-bidirectional-forward-reverse.js +++ b/eg/esc-bidirectional-forward-reverse.js @@ -11,7 +11,7 @@ board.on("ready", () => { const throttle = new Sensor("A0"); const brake = new Button(4); - brake.on("press", esc.brake); + brake.on("press", () => esc.brake()); throttle.scale(0, 100).on("change", () => { // 2 Seconds for arming. diff --git a/eg/esc-bidirectional.js b/eg/esc-bidirectional.js index 6ac982667..8f9b73142 100644 --- a/eg/esc-bidirectional.js +++ b/eg/esc-bidirectional.js @@ -9,7 +9,7 @@ board.on("ready", () => { const throttle = new Sensor("A0"); const brake = new Button(4); - brake.on("press", esc.brake); + brake.on("press", () => esc.brake()); throttle.on("change", () => { esc.throttle(throttle.scaleTo(esc.pwmRange)); diff --git a/eg/esc-dualshock.js b/eg/esc-dualshock.js index 39537108c..c1f993928 100644 --- a/eg/esc-dualshock.js +++ b/eg/esc-dualshock.js @@ -2,7 +2,7 @@ const { Board, ESC, Fn } = require("../lib/johnny-five.js"); const dualShock = require("dualshock-controller"); const board = new Board(); -const controller = dualShock({ +const gamepad = dualShock({ config: "dualShock3", analogStickSmoothing: false }); @@ -12,11 +12,11 @@ board.on("ready", () => { let speed = 0; let last = null; - controller.on("connected", () => { - controller.isConnected = true; + gamepad.on("connected", () => { + gamepad.isConnected = true; }); - controller.on("dpadUp:press", () => { + gamepad.on("dpadUp:press", () => { if (last !== "up") { speed = 0; } else { @@ -26,7 +26,7 @@ board.on("ready", () => { last = "up"; }); - controller.on("dpadDown:press", () => { + gamepad.on("dpadDown:press", () => { if (last !== "down") { speed = 0; } else { @@ -36,13 +36,13 @@ board.on("ready", () => { last = "down"; }); - controller.on("circle:press", () => { + gamepad.on("circle:press", () => { last = null; speed = 0; esc.brake(); }); - controller.on("right:move", position => { + gamepad.on("right:move", position => { const y = Fn.scale(position.y, 255, 0, 0, 180) | 0; if (y > 100) { diff --git a/eg/led-array.js b/eg/led-array.js index 9472482e0..b98526df2 100644 --- a/eg/led-array.js +++ b/eg/led-array.js @@ -2,9 +2,9 @@ const {Board, Leds} = require("../lib/johnny-five.js"); const board = new Board(); board.on("ready", () => { - const array = new Leds([3, 5, 6]); + const leds = new Leds([3, 5, 6]); - array.pulse(); + leds.pulse(); }); /* @markdown diff --git a/eg/led-fade-animation.js b/eg/led-fade-animation.js index 42c4bdb1f..e520afe6f 100644 --- a/eg/led-fade-animation.js +++ b/eg/led-fade-animation.js @@ -15,7 +15,5 @@ board.on("ready", () => { }); // Toggle the led after 2 seconds (shown in ms) - board.wait(2000, () => { - led.fadeOut(); - }); + board.wait(2000, () => led.fadeOut()); }); diff --git a/eg/motobot.js b/eg/motobot.js index 2480425c7..d5c80a0c3 100644 --- a/eg/motobot.js +++ b/eg/motobot.js @@ -37,11 +37,11 @@ board.on("ready", () => { motors.b.rev(speed * 0.75); } - commands = [].slice.call(arguments); + commands = Array.from(arguments); } else { if (ch >= 1 && ch <= 9) { speed = Fn.scale(ch, 1, 9, 0, 255); - controller.apply(null, commands); + controller(...commands); } } } diff --git a/eg/motor-hbridge-dual.js b/eg/motor-hbridge-dual.js index b882a0a44..749485b49 100644 --- a/eg/motor-hbridge-dual.js +++ b/eg/motor-hbridge-dual.js @@ -7,6 +7,7 @@ const {Board, Motors} = require("../lib/johnny-five.js"); const board = new Board(); +const invertPWM = true; board.on("ready", () => { /** @@ -14,8 +15,8 @@ board.on("ready", () => { * Motor B: PWM 5, dir 4 */ const motors = new Motors([ - { pins: { dir: 12, pwm: 11 }, invertPWM: true }, - { pins: { dir: 4, pwm: 5}, invertPWM: true } + { pins: { dir: 12, pwm: 11 }, invertPWM }, + { pins: { dir: 4, pwm: 5}, invertPWM } ]); board.repl.inject({ diff --git a/eg/motor-sparkfun-edison-hbridge.js b/eg/motor-sparkfun-edison-hbridge.js index 5d6e477eb..a8b648457 100644 --- a/eg/motor-sparkfun-edison-hbridge.js +++ b/eg/motor-sparkfun-edison-hbridge.js @@ -1,5 +1,5 @@ const {Board, Motor} = require("../lib/johnny-five.js"); -var Edison = require("galileo-io"); +const Edison = require("galileo-io"); const board = new Board({ io: new Edison() }); diff --git a/eg/motor-vnh5019.js b/eg/motor-vnh5019.js index a55ed92c2..76ad68f92 100644 --- a/eg/motor-vnh5019.js +++ b/eg/motor-vnh5019.js @@ -2,7 +2,7 @@ const {Board, Motor} = require("../lib/johnny-five.js"); const board = new Board(); board.on("ready", () => { - + // You can configure with explicit pins settings const m1 = new Motor({ pins: { @@ -25,9 +25,9 @@ board.on("ready", () => { }); // "start" events fire when the motor is started. - [m1, m2].forEach( (motor, index) => { + [m1, m2].forEach((motor, index) => { motor.on("start", () => { - console.log("start motor " + (index+1)); + console.log(`start motor ${index+1}`); // Demonstrate motor stop in 2 seconds this.wait(2000, motor.stop); @@ -35,7 +35,7 @@ board.on("ready", () => { }); [m1, m2].forEach( motor => { - + // "stop" events fire when the motor is stopped. motor.on("stop", () => console.log("stop")); }); diff --git a/eg/motors-EVS_EV3.js b/eg/motors-EVS_EV3.js index bdd3dd2e9..f317b7e94 100644 --- a/eg/motors-EVS_EV3.js +++ b/eg/motors-EVS_EV3.js @@ -1,12 +1,13 @@ -var five = require("../lib/johnny-five.js"); -var board = new five.Board(); +const {Board, Motors} = require("../lib/johnny-five.js"); +const board = new Board(); +const controller = "EVS_EV3"; -board.on("ready", function() { - var motors = new five.Motors([{ - controller: "EVS_EV3", +board.on("ready", () => { + const motors = new Motors([{ + controller, pin: "BAM1" }, { - controller: "EVS_EV3", + controller, pin: "BBM1" }, ]);