Skip to content

Commit ca68b6e

Browse files
dtexrwaldron
authored andcommitted
Update Switch examples
1 parent 5933b18 commit ca68b6e

8 files changed

+90
-65
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
286286
- [Button - Options](https://github.com/rwaldron/johnny-five/blob/master/docs/button-options.md)
287287
- [Button - Pullup](https://github.com/rwaldron/johnny-five/blob/master/docs/button-pullup.md)
288288
- [Buttons - Collection w/ AT42QT1070](https://github.com/rwaldron/johnny-five/blob/master/docs/button-collection-AT42QT1070.md)
289+
- [Switch](https://github.com/rwaldron/johnny-five/blob/master/docs/switch.md)
289290
- [Switch - Magnetic Door](https://github.com/rwaldron/johnny-five/blob/master/docs/switch-magnetic-door.md)
290291
- [Switch - Tilt SW-200D](https://github.com/rwaldron/johnny-five/blob/master/docs/switch-tilt-SW_200D.md)
291292
- [Toggle Switch](https://github.com/rwaldron/johnny-five/blob/master/docs/toggle-switch.md)

docs/switch-magnetic-door.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,14 @@ node eg/switch-magnetic-door.js
2929

3030

3131
```javascript
32-
var five = require("johnny-five");
33-
var board = new five.Board();
32+
const {Board, Switch} = require("johnny-five");
33+
const board = new Board();
3434

35-
board.on("ready", function() {
35+
board.on("ready", () => {
3636
// Contact Mode: Normally Open (default!)
37-
var sw = new five.Switch(7);
38-
39-
sw.on("open", function() {
40-
console.log("open");
41-
});
42-
43-
sw.on("close", function() {
44-
console.log("close");
45-
});
37+
const sw = new Switch(7);
38+
sw.on("open", () => console.log("open"));
39+
sw.on("close", () => console.log("close"));
4640
});
4741

4842
```

docs/switch-tilt-SW_200D.md

+7-14
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,24 @@ node eg/switch-tilt-SW_200D.js
2929

3030

3131
```javascript
32-
var five = require("johnny-five");
33-
var board = new five.Board();
34-
var tilt;
32+
const {Board, Button} = require("johnny-five");
33+
const board = new Board();
3534

36-
board.on("ready", function() {
37-
tilt = new five.Button(2); // digital pin 2
35+
board.on("ready", () => {
36+
const tilt = new Button(2); // digital pin 2
3837

3938
board.repl.inject({
4039
button: tilt
4140
});
4241

4342
// tilt the breadboard to the right, towards to the ground pin
44-
tilt.on("down", function() {
45-
console.log("down");
46-
});
43+
tilt.on("down", () => console.log("down"));
4744

4845
// tilt and hold
49-
tilt.on("hold", function() {
50-
console.log("hold");
51-
});
46+
tilt.on("hold", () => console.log("hold"));
5247

5348
// tilt back the breadboard to the stable position
54-
tilt.on("up", function() {
55-
console.log("up");
56-
});
49+
tilt.on("up", () => console.log("up"));
5750
});
5851

5952
```

docs/switch.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!--remove-start-->
2+
3+
# Switch
4+
5+
<!--remove-end-->
6+
7+
8+
9+
10+
11+
12+
13+
14+
Run this example from the command line with:
15+
```bash
16+
node eg/switch.js
17+
```
18+
19+
20+
```javascript
21+
const {Board, Led, Switch} = require("johnny-five");
22+
const board = new Board();
23+
24+
board.on("ready", () => {
25+
const spdt = new Switch(8);
26+
const led = new Led(13);
27+
28+
spdt.on("open", () => led.off());
29+
spdt.on("close", () => led.on());
30+
});
31+
32+
```
33+
34+
35+
36+
37+
38+
39+
40+
41+
&nbsp;
42+
43+
<!--remove-start-->
44+
45+
## License
46+
Copyright (c) 2012-2014 Rick Waldron <[email protected]>
47+
Licensed under the MIT license.
48+
Copyright (c) 2015-2019 The Johnny-Five Contributors
49+
Licensed under the MIT license.
50+
51+
<!--remove-end-->

eg/switch-magnetic-door.js

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

4-
board.on("ready", function() {
4+
board.on("ready", () => {
55
// Contact Mode: Normally Open (default!)
6-
var sw = new five.Switch(7);
7-
8-
sw.on("open", function() {
9-
console.log("open");
10-
});
11-
12-
sw.on("close", function() {
13-
console.log("close");
14-
});
6+
const sw = new Switch(7);
7+
sw.on("open", () => console.log("open"));
8+
sw.on("close", () => console.log("close"));
159
});

eg/switch-tilt-SW_200D.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
var five = require("../lib/johnny-five.js");
2-
var board = new five.Board();
3-
var tilt;
1+
const {Board, Button} = require("../lib/johnny-five.js");
2+
const board = new Board();
43

5-
board.on("ready", function() {
6-
tilt = new five.Button(2); // digital pin 2
4+
board.on("ready", () => {
5+
const tilt = new Button(2); // digital pin 2
76

87
board.repl.inject({
98
button: tilt
109
});
1110

1211
// tilt the breadboard to the right, towards to the ground pin
13-
tilt.on("down", function() {
14-
console.log("down");
15-
});
12+
tilt.on("down", () => console.log("down"));
1613

1714
// tilt and hold
18-
tilt.on("hold", function() {
19-
console.log("hold");
20-
});
15+
tilt.on("hold", () => console.log("hold"));
2116

2217
// tilt back the breadboard to the stable position
23-
tilt.on("up", function() {
24-
console.log("up");
25-
});
18+
tilt.on("up", () => console.log("up"));
2619
});

eg/switch.js

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

4-
board.on("ready", function() {
5-
var spdt = new five.Switch(8);
6-
var led = new five.Led(13);
7-
8-
spdt.on("open", function() {
9-
led.off();
10-
});
11-
12-
spdt.on("close", function() {
13-
led.on();
14-
});
4+
board.on("ready", () => {
5+
const spdt = new Switch(8);
6+
const led = new Led(13);
7+
8+
spdt.on("open", () => led.off());
9+
spdt.on("close", () => led.on());
1510
});

tpl/programs.json

+4
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@
564564
{
565565
"file": "switch-tilt-SW_200D.js",
566566
"title": "Switch - Tilt SW-200D"
567+
},
568+
{
569+
"file": "switch.js",
570+
"title": "Switch"
567571
}
568572
]
569573
},

0 commit comments

Comments
 (0)