Skip to content

Commit

Permalink
update syntax on led examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjgill authored and rwaldron committed Aug 21, 2019
1 parent db9a603 commit 1af10e9
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 94 deletions.
28 changes: 14 additions & 14 deletions docs/led-demo-sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ node eg/led-demo-sequence.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
var led;
const {Board, Led} = require("johnny-five");
const board = new Board();
let led;

// Do we want the sequence to loop?
var loop = true;
const loop = true;

// Create a simple demo sequece that calls various
// five.Led methods with specified arguments and
// let it run for the given duration (defaults to 3 seconds).
var demoSequence = [{
const demoSequence = [{
method: "pulse",
args: [1000],
duration: 5000
Expand All @@ -55,7 +55,7 @@ var demoSequence = [{
method: "fadeIn",
args: [
2000,
function() {
() => {
console.log("fadeIn complete!");
}
],
Expand All @@ -64,7 +64,7 @@ var demoSequence = [{
method: "fadeOut",
args: [
5000,
function() {
() => {
console.log("fadeOut complete!");
}
],
Expand All @@ -82,15 +82,15 @@ var demoSequence = [{
function execute(step) {

// Grab everything we need for this step
var method = demoSequence[step].method;
var args = demoSequence[step].args;
var duration = demoSequence[step].duration || 3000;
const method = demoSequence[step].method;
const args = demoSequence[step].args;
const duration = demoSequence[step].duration || 3000;

// Just print out what we're executing
console.log("led." + method + "(" + (args ? args.join() : "") + ")");

// Make the actual call to the LED
five.Led.prototype[method].apply(led, args);
Led.prototype[method].apply(led, args);

// Increment the step
step++;
Expand All @@ -106,14 +106,14 @@ function execute(step) {
}

// Recursively call the next step after specified duration
board.wait(duration, function() {
board.wait(duration, () => {
execute(step);
});
}

board.on("ready", function() {
board.on("ready", () => {
// Defaults to pin 11 (must be PWM)
led = new five.Led(process.argv[2] || 11);
led = new Led(process.argv[2] || 11);

// Kick off the first step
execute(0);
Expand Down
11 changes: 5 additions & 6 deletions docs/led-fade-animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ node eg/led-fade-animation.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, Led} = require("johnny-five");
const board = new Board();

board.on("ready", function() {

var led = new five.Led(11);
const led = new Led(11);

led.fade({
easing: "linear",
duration: 1000,
cuePoints: [0, 0.2, 0.4, 0.6, 0.8, 1],
keyFrames: [0, 250, 25, 150, 100, 125],
onstop: function() {
onstop: () => {
console.log("Animation stopped");
}
});

// Toggle the led after 2 seconds (shown in ms)
this.wait(2000, function() {
this.wait(2000, () => {
led.fadeOut();
});
});
Expand Down
17 changes: 8 additions & 9 deletions docs/led-fade-callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@ node eg/led-fade-callback.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, Leds} = require("johnny-five");
const board = new Board();

board.on("ready", function() {
// Set up the following PWM pins as LEDs.
// Fade an LED out, and the complete callback will start
// fading the next LED in sequence out, and so on.
// If randomFade is true, then fading will happen in random
// order instead of sequentially.
var leds = new five.Leds([11, 10, 9, 6, 5, 3]);
var timing = 250;
var randomFade = true;
var fadeIndex = 0;
var ledCount = leds.length;
var i;
const leds = new Leds([11, 10, 9, 6, 5, 3]);
const timing = 250;
const randomFade = true;
const ledCount = leds.length;
let fadeIndex = 0;

function fadeNext() {
var candidateIndex = fadeIndex;
let candidateIndex = fadeIndex;
leds[fadeIndex].fadeIn(timing);

// Determine the next LED to fade
Expand Down
9 changes: 4 additions & 5 deletions docs/led-fade.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ node eg/led-fade.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, Led} = require("johnny-five");
const board = new Board();

board.on("ready", function() {

var led = new five.Led(11);
const led = new Led(11);

led.fadeIn();

// Toggle the led after 5 seconds (shown in ms)
this.wait(5000, function() {
this.wait(5000, () => {
led.fadeOut();
});
});
Expand Down
11 changes: 5 additions & 6 deletions docs/led-pulse-animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ node eg/led-pulse-animation.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, Led} = require("johnny-five");
const board = new Board();

board.on("ready", function() {

// Create a standard `led` component
// on a valid pwm pin
var led = new five.Led(11);
const led = new Led(11);

// Instead of passing a time and rate, you can
// pass any valid Animation() segment opts object
Expand All @@ -50,14 +49,14 @@ board.on("ready", function() {
duration: 3000,
cuePoints: [0, 0.2, 0.4, 0.6, 0.8, 1],
keyFrames: [0, 10, 0, 50, 0, 255],
onstop: function() {
onstop: () => {
console.log("Animation stopped");
}
});

// Stop and turn off the led pulse loop after
// 12 seconds (shown in ms)
this.wait(12000, function() {
this.wait(12000, () => {

// stop() terminates the interval
// off() shuts the led off
Expand Down
13 changes: 6 additions & 7 deletions docs/led-slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ node eg/led-slider.js


```javascript
var five = require("johnny-five");
var board = new five.Board();
const {Board, Led, Sensor} = require("johnny-five");
const board = new Board();

board.on("ready", function() {

var slider = new five.Sensor("A0");
var led = new five.Led(11);
const slider = new Sensor("A0");
const led = new Led(11);

// Scale the sensor's value to the LED's brightness range
slider.scale([0, 255]).on("data", function() {
led.brightness(this.value);
slider.scale([0, 255]).on("data", () => {
led.brightness(slider.value);
});
});

Expand Down
28 changes: 14 additions & 14 deletions eg/led-demo-sequence.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
var led;
const {Board, Led} = require("../lib/johnny-five.js");
const board = new Board();
let led;

// Do we want the sequence to loop?
var loop = true;
const loop = true;

// Create a simple demo sequece that calls various
// five.Led methods with specified arguments and
// let it run for the given duration (defaults to 3 seconds).
var demoSequence = [{
const demoSequence = [{
method: "pulse",
args: [1000],
duration: 5000
Expand All @@ -20,7 +20,7 @@ var demoSequence = [{
method: "fadeIn",
args: [
2000,
function() {
() => {
console.log("fadeIn complete!");
}
],
Expand All @@ -29,7 +29,7 @@ var demoSequence = [{
method: "fadeOut",
args: [
5000,
function() {
() => {
console.log("fadeOut complete!");
}
],
Expand All @@ -47,15 +47,15 @@ var demoSequence = [{
function execute(step) {

// Grab everything we need for this step
var method = demoSequence[step].method;
var args = demoSequence[step].args;
var duration = demoSequence[step].duration || 3000;
const method = demoSequence[step].method;
const args = demoSequence[step].args;
const duration = demoSequence[step].duration || 3000;

// Just print out what we're executing
console.log("led." + method + "(" + (args ? args.join() : "") + ")");

// Make the actual call to the LED
five.Led.prototype[method].apply(led, args);
Led.prototype[method].apply(led, args);

// Increment the step
step++;
Expand All @@ -71,14 +71,14 @@ function execute(step) {
}

// Recursively call the next step after specified duration
board.wait(duration, function() {
board.wait(duration, () => {
execute(step);
});
}

board.on("ready", function() {
board.on("ready", () => {
// Defaults to pin 11 (must be PWM)
led = new five.Led(process.argv[2] || 11);
led = new Led(process.argv[2] || 11);

// Kick off the first step
execute(0);
Expand Down
11 changes: 5 additions & 6 deletions eg/led-fade-animation.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, Led} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {

var led = new five.Led(11);
const led = new Led(11);

led.fade({
easing: "linear",
duration: 1000,
cuePoints: [0, 0.2, 0.4, 0.6, 0.8, 1],
keyFrames: [0, 250, 25, 150, 100, 125],
onstop: function() {
onstop: () => {
console.log("Animation stopped");
}
});

// Toggle the led after 2 seconds (shown in ms)
this.wait(2000, function() {
this.wait(2000, () => {
led.fadeOut();
});
});
17 changes: 8 additions & 9 deletions eg/led-fade-callback.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, Leds} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
// Set up the following PWM pins as LEDs.
// Fade an LED out, and the complete callback will start
// fading the next LED in sequence out, and so on.
// If randomFade is true, then fading will happen in random
// order instead of sequentially.
var leds = new five.Leds([11, 10, 9, 6, 5, 3]);
var timing = 250;
var randomFade = true;
var fadeIndex = 0;
var ledCount = leds.length;
var i;
const leds = new Leds([11, 10, 9, 6, 5, 3]);
const timing = 250;
const randomFade = true;
const ledCount = leds.length;
let fadeIndex = 0;

function fadeNext() {
var candidateIndex = fadeIndex;
let candidateIndex = fadeIndex;
leds[fadeIndex].fadeIn(timing);

// Determine the next LED to fade
Expand Down
9 changes: 4 additions & 5 deletions eg/led-fade.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, Led} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {

var led = new five.Led(11);
const led = new Led(11);

led.fadeIn();

// Toggle the led after 5 seconds (shown in ms)
this.wait(5000, function() {
this.wait(5000, () => {
led.fadeOut();
});
});
Loading

0 comments on commit 1af10e9

Please sign in to comment.