Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

led: updated led-rgb examples syntax #1615

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ To get you up and running quickly, we provide a variety of examples for using ea

To interactively navigate the examples, visit the [Johnny-Five examples](http://johnny-five.io/examples/) page on the official website. If you want to link directly to the examples in this repo, you can use one of the following links.

**There are presently 362 example programs with code and diagrams!**
**There are presently 364 example programs with code and diagrams!**

<!--extract-start:examples-->

Expand Down Expand Up @@ -324,8 +324,8 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://

### Proximity
- [Proximity](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity.md)
- [Proximity - EVShield EV3 (IR)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_IR.md)
- [Proximity - EVShield EV3 (IR)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_IR-alert.md)
- [Proximity - EVShield EV3 (IR)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_IR.md)
- [Proximity - EVShield EV3 (Ultrasonic)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_US.md)
- [Proximity - EVShield EV3 (Ultrasonic)](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-EVS_EV3_US-alert.md)
- [Proximity - GP2Y0A710K0F](https://github.com/rwaldron/johnny-five/blob/master/docs/proximity-GP2Y0A710K0F.md)
Expand Down
14 changes: 7 additions & 7 deletions docs/led-rainbow.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ node eg/led-rainbow.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 rgb = new five.Led.RGB([6, 5, 3]);
var index = 0;
var rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];
board.on("ready", () => {
const rgb = new Led.RGB([6, 5, 3]);
let index = 0;
const rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];

this.loop(1000, function() {
board.loop(1000, () => {
rgb.color(rainbow[index++]);
if (index === rainbow.length) {
index = 0;
Expand Down
12 changes: 6 additions & 6 deletions docs/led-rgb-BLINKM.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ node eg/led-rgb-BLINKM.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() {
// Initialize the RGB LED
var rgb = new five.Led.RGB({
const rgb = new Led.RGB({
controller: "BLINKM"
});
var index = 0;
var rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];
let index = 0;
const rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];

this.loop(1000, function() {
board.loop(1000, () => {
if (index + 1 === rainbow.length) {
index = 0;
}
Expand Down
16 changes: 6 additions & 10 deletions docs/led-rgb-anode-PCA9685.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ node eg/led-rgb-anode-PCA9685.js


```javascript
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
const {Board, Led} = require("johnny-five");
const board = new Board();

board.on("ready", () => {
// Initialize the RGB LED
var led = new five.Led.RGB({
const led = new Led.RGB({
controller: "PCA9685",
isAnode: true,
pins: {
Expand All @@ -55,23 +54,20 @@ board.on("ready", function() {
// green: g,
// blue: b
// }
// var led = new five.Led.RGB({
// const led = new Led.RGB({
// pins: [2, 1, 0],
// isAnode: true,
// controller: "PCA9685"
// });

// Add led to REPL (optional)
this.repl.inject({
led: led
});
board.repl.inject({ led });

// Turn it on and set the initial color
led.on();
led.color("#FF0000");

led.blink(1000);

});

```
Expand Down
13 changes: 5 additions & 8 deletions docs/led-rgb-anode.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ node eg/led-rgb-anode.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 anode = new five.Led.RGB({
board.on("ready", () => {
const anode = new Led.RGB({
pins: {
red: 6,
green: 5,
Expand All @@ -47,16 +47,13 @@ board.on("ready", function() {
});

// Add led to REPL (optional)
this.repl.inject({
anode: anode
});
board.repl.inject({ anode });

// Turn it on and set the initial color
anode.on();
anode.color("#FF0000");

anode.blink(1000);

});

```
Expand Down
17 changes: 8 additions & 9 deletions docs/led-rgb-intensity.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ node eg/led-rgb-intensity.js


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

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

// Initialize the RGB LED
var led = new five.Led.RGB([6, 5, 3]);
const led = new Led.RGB([6, 5, 3]);

// Set to full intensity red
console.log("100% red");
Expand All @@ -49,25 +48,25 @@ board.on("ready", function() {
temporal.queue([{
// After 3 seconds, dim to 30% intensity
wait: 3000,
task: function() {
task() {
console.log("30% red");
led.intensity(30);
}
}, {
// 3 secs then turn blue, still 30% intensity
wait: 3000,
task: function() {
task() {
console.log("30% blue");
led.color("#0000FF");
}
}, {
// Another 3 seconds, go full intensity blue
wait: 3000,
task: function() {
task() {
console.log("100% blue");
led.intensity(100);
}
}, ]);
}]);
});

```
Expand Down
16 changes: 6 additions & 10 deletions docs/led-rgb.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ node eg/led-rgb.js


```javascript
var five = require("johnny-five");


five.Board().on("ready", function() {
const {Board, Led} = require("johnny-five");
const board = new Board();

board.on("ready", () => {
// Initialize the RGB LED
var led = new five.Led.RGB({
const led = new Led.RGB({
pins: {
red: 6,
green: 5,
Expand All @@ -55,19 +54,16 @@ five.Board().on("ready", function() {
// green: g,
// blue: b
// }
//var led = new five.Led.RGB([3,5,6]);
// const led = new Led.RGB([3,5,6]);

// Add led to REPL (optional)
this.repl.inject({
led: led
});
board.repl.inject({ led });

// Turn it on and set the initial color
led.on();
led.color("#FF0000");

led.blink(1000);

});

```
Expand Down
14 changes: 7 additions & 7 deletions eg/led-rainbow.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 rgb = new five.Led.RGB([6, 5, 3]);
var index = 0;
var rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];
board.on("ready", () => {
const rgb = new Led.RGB([6, 5, 3]);
let index = 0;
const rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];

this.loop(1000, function() {
board.loop(1000, () => {
rgb.color(rainbow[index++]);
if (index === rainbow.length) {
index = 0;
Expand Down
12 changes: 6 additions & 6 deletions eg/led-rgb-BLINKM.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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() {
// Initialize the RGB LED
var rgb = new five.Led.RGB({
const rgb = new Led.RGB({
controller: "BLINKM"
});
var index = 0;
var rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];
let index = 0;
const rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];

this.loop(1000, function() {
board.loop(1000, () => {
if (index + 1 === rainbow.length) {
index = 0;
}
Expand Down
16 changes: 6 additions & 10 deletions eg/led-rgb-anode-PCA9685.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();

board.on("ready", function() {
const {Board, Led} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", () => {
// Initialize the RGB LED
var led = new five.Led.RGB({
const led = new Led.RGB({
controller: "PCA9685",
isAnode: true,
pins: {
Expand All @@ -22,21 +21,18 @@ board.on("ready", function() {
// green: g,
// blue: b
// }
// var led = new five.Led.RGB({
// const led = new Led.RGB({
// pins: [2, 1, 0],
// isAnode: true,
// controller: "PCA9685"
// });

// Add led to REPL (optional)
this.repl.inject({
led: led
});
board.repl.inject({ led });

// Turn it on and set the initial color
led.on();
led.color("#FF0000");

led.blink(1000);

});
13 changes: 5 additions & 8 deletions eg/led-rgb-anode.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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 anode = new five.Led.RGB({
board.on("ready", () => {
const anode = new Led.RGB({
pins: {
red: 6,
green: 5,
Expand All @@ -12,14 +12,11 @@ board.on("ready", function() {
});

// Add led to REPL (optional)
this.repl.inject({
anode: anode
});
board.repl.inject({ anode });

// Turn it on and set the initial color
anode.on();
anode.color("#FF0000");

anode.blink(1000);

});
17 changes: 8 additions & 9 deletions eg/led-rgb-intensity.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var temporal = require("temporal");
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const temporal = require("temporal");
const {Board, Led} = require("../lib/johnny-five.js");
const board = new Board();

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

// Initialize the RGB LED
var led = new five.Led.RGB([6, 5, 3]);
const led = new Led.RGB([6, 5, 3]);

// Set to full intensity red
console.log("100% red");
Expand All @@ -14,23 +13,23 @@ board.on("ready", function() {
temporal.queue([{
// After 3 seconds, dim to 30% intensity
wait: 3000,
task: function() {
task() {
console.log("30% red");
led.intensity(30);
}
}, {
// 3 secs then turn blue, still 30% intensity
wait: 3000,
task: function() {
task() {
console.log("30% blue");
led.color("#0000FF");
}
}, {
// Another 3 seconds, go full intensity blue
wait: 3000,
task: function() {
task() {
console.log("100% blue");
led.intensity(100);
}
}, ]);
}]);
});
Loading