Skip to content

Commit

Permalink
Examples: miscellaneous nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Aug 21, 2019
1 parent 4ceca23 commit 687d032
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
16 changes: 8 additions & 8 deletions eg/arduino-starter-kit/light-theremin.js
Original file line number Diff line number Diff line change
@@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion eg/esc-bidirectional-forward-reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion eg/esc-bidirectional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

This comment has been minimized.

Copy link
@dtex

dtex Aug 21, 2019

Collaborator

@rwaldron Just wanted to ask about this particular nit. I've been using the style brake.on("press", esc.brake); when there is no param. Should I stop?


throttle.on("change", () => {
esc.throttle(throttle.scaleTo(esc.pwmRange));
Expand Down
14 changes: 7 additions & 7 deletions eg/esc-dualshock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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 {
Expand All @@ -26,7 +26,7 @@ board.on("ready", () => {
last = "up";
});

controller.on("dpadDown:press", () => {
gamepad.on("dpadDown:press", () => {
if (last !== "down") {
speed = 0;
} else {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions eg/led-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions eg/led-fade-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
4 changes: 2 additions & 2 deletions eg/motobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions eg/motor-hbridge-dual.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

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

board.on("ready", () => {
/**
* Motor A: PWM 11, dir 12
* 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({
Expand Down
2 changes: 1 addition & 1 deletion eg/motor-sparkfun-edison-hbridge.js
Original file line number Diff line number Diff line change
@@ -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()
});
Expand Down
8 changes: 4 additions & 4 deletions eg/motor-vnh5019.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -25,17 +25,17 @@ 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);
});
});

[m1, m2].forEach( motor => {

// "stop" events fire when the motor is stopped.
motor.on("stop", () => console.log("stop"));
});
Expand Down
13 changes: 7 additions & 6 deletions eg/motors-EVS_EV3.js
Original file line number Diff line number Diff line change
@@ -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"
}, ]);

Expand Down

0 comments on commit 687d032

Please sign in to comment.