Skip to content

Latest commit

 

History

History
81 lines (44 loc) · 1.24 KB

toggle-switch.md

File metadata and controls

81 lines (44 loc) · 1.24 KB

Toggle Switch

Breadboard for "Toggle Switch"

docs/breadboard/toggle-switch.png

Fritzing diagram: docs/breadboard/toggle-switch.fzz

 

Run this example from the command line with:

node eg/toggle-switch.js
var five = require("johnny-five");
var board = new five.Board();

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

  // Create a new `switch` hardware instance.
  // This example allows the switch module to
  // create a completely default instance
  var toggle = new five.Switch(8);

  // Inject the `switch` hardware into
  // the Repl instance's context;
  // allows direct command line access
  board.repl.inject({
    toggle: toggle
  });

  // Switch Event API

  // "closed" the switch is closed
  toggle.on("close", function() {
    console.log("closed");
  });

  // "open" the switch is opened
  toggle.on("open", function() {
    console.log("open");
  });
});

 

License

Copyright (c) 2012-2014 Rick Waldron [email protected] Licensed under the MIT license. Copyright (c) 2015-2023 The Johnny-Five Contributors Licensed under the MIT license.