-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
90 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
|
||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
| ||
|
||
<!--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--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters