Skip to content

Commit f3ddbb5

Browse files
committed
Examples: Accelerometer nitpicking, Board, Exander, misc.
1 parent 87cbae2 commit f3ddbb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+314
-292
lines changed

eg/accelerometer-LIS3DH.js

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

44
board.on("ready", () => {

eg/accelerometer-MMA8452.js

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

44
board.on("ready", () => {

eg/accelerometer-adxl335.js

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

44
board.on("ready", () => {

eg/accelerometer-adxl345.js

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

44
board.on("ready", () => {

eg/accelerometer-mma7361.js

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

44
board.on("ready", () => {

eg/accelerometer-mpu6050.js

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

44
board.on("ready", () => {

eg/accelerometer-pan-tilt.js

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

44
board.on("ready", () => {

eg/accelerometer.js

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

44
board.on("ready", () => {

eg/barometer-BMP085.js

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

44
board.on("ready", () => {

eg/barometer-BMP180.js

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

44
board.on("ready", () => {

eg/barometer-MS5611.js

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

44
board.on("ready", () => {

eg/barometer-mpl115a2.js

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

44
board.on("ready", () => {

eg/barometer-mpl3115a2.js

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

44
board.on("ready", () => {

eg/board-cleanup.js

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

4-
board.on("ready", function() {
5-
var led = new five.Led(13);
4+
board.on("ready", () => {
5+
const led = new Led(13);
66
led.on();
77

88

9-
this.on("exit", function() {
9+
board.on("exit", () => {
1010
led.off();
1111
});
1212
});

eg/board-multi.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var five = require("../lib/johnny-five.js");
2-
var boards = new five.Boards(["A", "B"]);
1+
const { Boards, Led } = require("../lib/johnny-five.js");
2+
const boards = new Boards(["A", "B"]);
33

44
// Create 2 board instances with IDs "A" & "B"
55
boards.on("ready", function() {
@@ -8,22 +8,22 @@ boards.on("ready", function() {
88
// (connected and available for communication)
99

1010
// Access them by their ID:
11-
var led = new five.Led({
11+
const led = new Led({
12+
board: board.byId("A"),
1213
pin: 13,
13-
board: this.byId("A")
1414
});
1515

1616
led.blink();
1717

1818
// |this| is an array-like object containing references
1919
// to each initialized board.
20-
this.each(function(board) {
20+
boards.each(board => {
2121
if (board.id === "B") {
2222
// Initialize an Led instance on pin 13 of
2323
// each initialized board and strobe it.
24-
var led = new five.Led({
24+
const led = new Led({
2525
pin: 13,
26-
board: board
26+
board
2727
});
2828

2929
led.blink();

eg/board-sampling-interval.js

+4-4
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 } = require("../lib/johnny-five.js");
2+
const board = new Board();
33

4-
board.on("ready", function() {
4+
board.on("ready", () => {
55

66
// Use the board's `samplingInterval(ms)` to
77
// control the actual MCU sampling rate.
88
//
99
// This will limit sampling of all Analog Input
1010
// and I2C sensors to once per second (1000 milliseconds)
11-
this.samplingInterval(1000);
11+
board.samplingInterval(1000);
1212

1313

1414
// Keep in mind that calling this method

eg/board-with-port.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
var five = require("../lib/johnny-five.js");
1+
const { Board } = require("../lib/johnny-five.js");
22

33
// Johnny-Five will try its hardest to detect the port for you,
44
// however you may also explicitly specify the port by passing
55
// it as an optional property to the Board constructor:
6-
var board = new five.Board({
6+
const board = new Board({
77
port: "/dev/cu.usbmodem1411"
88
});
99

1010
// The board's pins will not be accessible until
1111
// the board has reported that it is ready
12-
board.on("ready", function() {
13-
this.pinMode(13, this.MODES.OUTPUT);
12+
board.on("ready", () => {
13+
board.pinMode(13, board.MODES.OUTPUT);
1414

15-
this.loop(500, () => {
15+
board.loop(500, () => {
1616
// Whatever the last value was, write the opposite
17-
this.digitalWrite(13, this.pins[13].value ? 0 : 1);
17+
board.digitalWrite(13, board.pins[13].value ? 0 : 1);
1818
});
1919
});

eg/board.js

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

44
// The board's pins will not be accessible until
55
// the board has reported that it is ready
6-
board.on("ready", function() {
6+
board.on("ready", () => {
77
console.log("Ready!");
88

9-
var led = new five.Led(13);
9+
const led = new five.Led(13);
1010
led.blink(500);
1111
});

eg/color-display-in-lcd-EVS_NXT.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
var exec = require("child_process").exec;
2-
var five = require("../lib/johnny-five.js");
3-
var board = new five.Board();
1+
const {Board, Color, LCD} = require("../lib/johnny-five.js");
2+
const board = new Board();
43

5-
board.on("ready", function() {
6-
var lcd = new five.LCD({
4+
board.on("ready", () => {
5+
const lcd = new LCD({
76
controller: "JHD1313M1"
87
});
98

10-
var color = new five.Color({
9+
const color = new Color({
1110
controller: "EVS_NXT",
12-
pin: "BAS1"
11+
pin: "BBS2"
1312
});
1413

15-
color.on("change", function() {
16-
lcd.bgColor(this.rgb);
17-
// console.log("Color: ", this.rgb);
14+
color.on("change", () => {
15+
lcd.bgColor(color.rgb);
1816
});
1917
});

eg/compass-MAG3110-tessel.js

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

eg/compass-MAG3110.js

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

44
board.on("ready", () => {

eg/compass-hmc5883l.js

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

44
board.on("ready", () => {

eg/compass-hmc6352.js

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

44
board.on("ready", () => {

eg/compass.js

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

44
board.on("ready", () => {

eg/edison-io-arduino.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var five = require("../lib/johnny-five.js");
2-
var Edison = require("edison-io");
3-
var board = new five.Board({
1+
const { Board, Led } = require("../lib/johnny-five.js");
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 led = new five.Led(13);
7+
board.on("ready", () => {
8+
const led = new Led(13);
99
led.blink();
1010
});
1111

eg/edison-io-miniboard.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var five = require("../lib/johnny-five.js");
2-
var Edison = require("edison-io");
3-
var board = new five.Board({
1+
const { Board, Led } = require("../lib/johnny-five.js");
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 led = new five.Led(1);
7+
board.on("ready", () => {
8+
const led = new Led(1);
99
led.blink();
1010
});
1111

eg/expander-74HC595.js

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

4-
board.on("ready", function() {
5-
var expander = new five.Expander({
4+
board.on("ready", () => {
5+
const expander = new Expander({
66
controller: "74HC595",
77
pins: {
88
data: 2,
@@ -11,11 +11,16 @@ board.on("ready", function() {
1111
}
1212
});
1313

14-
var virtual = new five.Board.Virtual(expander);
15-
var leds = new five.Leds({
16-
pins: [0, 1, 2, 3, 4, 5, 6, 7],
17-
board: virtual
18-
});
14+
const virtual = new Board.Virtual(expander);
15+
const leds = new Leds(
16+
Array.from(Array(8), (_, pin) =>
17+
({ pin, board: virtual })
18+
)
19+
);
1920

2021
leds.blink(500);
22+
23+
board.repl.inject({
24+
leds
25+
});
2126
});

eg/expander-ADS1115.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
var Barcli = require("barcli");
2-
var five = require("../lib/johnny-five");
3-
var board = new five.Board();
1+
const Barcli = require("barcli");
2+
const { Board, Expander, Sensor } = require("../lib/johnny-five");
3+
const board = new Board();
44

5-
board.on("ready", function() {
6-
var virtual = new five.Board.Virtual(
7-
new five.Expander("ADS1115")
5+
board.on("ready", () => {
6+
const virtual = new Board.Virtual(
7+
new Expander("ADS1115")
88
);
99

10-
virtual.io.analogPins.forEach(function(input) {
10+
virtual.io.analogPins.forEach(pin => {
1111

12-
var bar = new Barcli({ label: input, range: [0, 1023] });
12+
const bar = new Barcli({
13+
label: pin,
14+
range: [0, 1023]
15+
});
1316

1417
// Initialize a Sensor instance with
1518
// the virtual board created above
16-
var sensor = new five.Sensor({
17-
pin: input,
18-
board: virtual
19+
const sensor = new Sensor({
20+
board: virtual,
21+
pin,
1922
});
2023

2124
// Display all changes in the terminal
2225
// as a Barcli chart graph
23-
sensor.on("change", function() {
24-
bar.update(this.value);
26+
sensor.on("change", () => {
27+
bar.update(sensor.value);
2528
});
2629
});
2730
});

0 commit comments

Comments
 (0)