Breadboard for "Toggle Switch"


Fritzing diagram: 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
    toggle: toggle

  // Switch Event API

  // "closed" the switch is closed
  toggle.on("close", function() {

  // "open" the switch is opened
  toggle.on("open", function() {


Component Classes in this example:

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub