Skip to content

Commit

Permalink
Update Switch examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dtex authored and rwaldron committed Aug 23, 2019
1 parent 5933b18 commit ca68b6e
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 65 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
- [Button - Options](https://github.com/rwaldron/johnny-five/blob/master/docs/button-options.md)
- [Button - Pullup](https://github.com/rwaldron/johnny-five/blob/master/docs/button-pullup.md)
- [Buttons - Collection w/ AT42QT1070](https://github.com/rwaldron/johnny-five/blob/master/docs/button-collection-AT42QT1070.md)
- [Switch](https://github.com/rwaldron/johnny-five/blob/master/docs/switch.md)
- [Switch - Magnetic Door](https://github.com/rwaldron/johnny-five/blob/master/docs/switch-magnetic-door.md)
- [Switch - Tilt SW-200D](https://github.com/rwaldron/johnny-five/blob/master/docs/switch-tilt-SW_200D.md)
- [Toggle Switch](https://github.com/rwaldron/johnny-five/blob/master/docs/toggle-switch.md)
Expand Down
18 changes: 6 additions & 12 deletions docs/switch-magnetic-door.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,14 @@ node eg/switch-magnetic-door.js


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

board.on("ready", function() {
board.on("ready", () => {
// Contact Mode: Normally Open (default!)
var sw = new five.Switch(7);

sw.on("open", function() {
console.log("open");
});

sw.on("close", function() {
console.log("close");
});
const sw = new Switch(7);
sw.on("open", () => console.log("open"));
sw.on("close", () => console.log("close"));
});

```
Expand Down
21 changes: 7 additions & 14 deletions docs/switch-tilt-SW_200D.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,24 @@ node eg/switch-tilt-SW_200D.js


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

board.on("ready", function() {
tilt = new five.Button(2); // digital pin 2
board.on("ready", () => {
const tilt = new Button(2); // digital pin 2

board.repl.inject({
button: tilt
});

// tilt the breadboard to the right, towards to the ground pin
tilt.on("down", function() {
console.log("down");
});
tilt.on("down", () => console.log("down"));

// tilt and hold
tilt.on("hold", function() {
console.log("hold");
});
tilt.on("hold", () => console.log("hold"));

// tilt back the breadboard to the stable position
tilt.on("up", function() {
console.log("up");
});
tilt.on("up", () => console.log("up"));
});

```
Expand Down
51 changes: 51 additions & 0 deletions docs/switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--remove-start-->

# Switch

<!--remove-end-->








Run this example from the command line with:
```bash
node eg/switch.js
```


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

board.on("ready", () => {
const spdt = new Switch(8);
const led = new Led(13);

spdt.on("open", () => led.off());
spdt.on("close", () => led.on());
});

```








&nbsp;

<!--remove-start-->

## License
Copyright (c) 2012-2014 Rick Waldron <waldron.rick@gmail.com>
Licensed under the MIT license.
Copyright (c) 2015-2019 The Johnny-Five Contributors
Licensed under the MIT license.

<!--remove-end-->
18 changes: 6 additions & 12 deletions eg/switch-magnetic-door.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, Switch} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
board.on("ready", () => {
// Contact Mode: Normally Open (default!)
var sw = new five.Switch(7);

sw.on("open", function() {
console.log("open");
});

sw.on("close", function() {
console.log("close");
});
const sw = new Switch(7);
sw.on("open", () => console.log("open"));
sw.on("close", () => console.log("close"));
});
21 changes: 7 additions & 14 deletions eg/switch-tilt-SW_200D.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
var tilt;
const {Board, Button} = require("../lib/johnny-five.js");
const board = new Board();

board.on("ready", function() {
tilt = new five.Button(2); // digital pin 2
board.on("ready", () => {
const tilt = new Button(2); // digital pin 2

board.repl.inject({
button: tilt
});

// tilt the breadboard to the right, towards to the ground pin
tilt.on("down", function() {
console.log("down");
});
tilt.on("down", () => console.log("down"));

// tilt and hold
tilt.on("hold", function() {
console.log("hold");
});
tilt.on("hold", () => console.log("hold"));

// tilt back the breadboard to the stable position
tilt.on("up", function() {
console.log("up");
});
tilt.on("up", () => console.log("up"));
});
21 changes: 8 additions & 13 deletions eg/switch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
var five = require("../lib/johnny-five.js");
var board = new five.Board();
const {Board, Led, Switch} = require("johnny-five.js");
const board = new Board();

board.on("ready", function() {
var spdt = new five.Switch(8);
var led = new five.Led(13);

spdt.on("open", function() {
led.off();
});

spdt.on("close", function() {
led.on();
});
board.on("ready", () => {
const spdt = new Switch(8);
const led = new Led(13);

spdt.on("open", () => led.off());
spdt.on("close", () => led.on());
});
4 changes: 4 additions & 0 deletions tpl/programs.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@
{
"file": "switch-tilt-SW_200D.js",
"title": "Switch - Tilt SW-200D"
},
{
"file": "switch.js",
"title": "Switch"
}
]
},
Expand Down

0 comments on commit ca68b6e

Please sign in to comment.