Skip to content

Latest commit

 

History

History
112 lines (67 loc) · 1.7 KB

motor-enable.md

File metadata and controls

112 lines (67 loc) · 1.7 KB

Motor - Enable Pin

Enable pin on 7

H-bridge example with enable connected to pin 7 instead of v+.

docs/breadboard/motor-enable.png

Fritzing diagram: docs/breadboard/motor-enable.fzz

 

Run this example from the command line with:

node eg/motor-enable.js
const {Board, Motor} = require("johnny-five");
const board = new Board();

board.on("ready", () => {
  /*
    // Motors with an enable pin must be initialized with a pins object

    new five.Motor({
      pins: {
        pwm: 3,
        dir: 12,
        enable: 7
      }
    });

   */

  const motor = new Motor({
    pins: {
      pwm: 3,
      dir: 12,
      enable: 7
    },
    invertPWM: true
  });

  board.repl.inject({
    motor
  });

  motor.on("stop", () => {
    console.log(`automated stop on timer: ${Date.now()}`);
  });

  motor.on("forward", () => {
    console.log(`forward: ${Date.now()}`);

    // enable the motor after 2 seconds
    board.wait(2000, motor.enable);
  });

  motor.on("enable", () => {
    console.log(`motor enabled: ${Date.now()}`);

    // enable the motor after 2 seconds
    board.wait(2000, motor.stop);
  });

  motor.on("disable", () => {
    console.log(`motor disabled: ${Date.now()}`);
  });

  // disable the motor
  motor.disable();

  // set the motor going forward full speed (nothing happen)
  motor.forward(255);
});

 

License

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