The ShiftRegister class constructs an object that represents a shift register.

Parameters

  • pins An array of pins in data, clock, latch, [reset] order

  • options An object of constructor parameters

    NameTypeValue/DescriptionDefaultRequired
    pinsObject{data, clock, latch, [reset]}Yes (either)
    pinsArray[data, clock, latch, [reset]]Yes (either)
    isAnodeBooleantrue or false. Initialize shift register to output for common anode device.falseNo

Shape

Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
pinsthe object containing the pin values for data, clock and latchNo
valuethe object containing the pin values for data, clock and latchYes
isAnodethe object containing the pin values for data, clock and latchYes

Component Initialization

Default

new five.ShiftRegister({
  pins: {
    data: 2,
    clock: 3,
    latch: 4
  }
});
new five.ShiftRegister({
  pins: [2, 3, 4]
});
new five.ShiftRegister([2, 3, 4]);

Shift Register Shift Register Seven Segment

Common Anode

new five.ShiftRegister({
  isAnode: true,
  pins: {
    data: 2,
    clock: 3,
    latch: 4
  }
});
new five.ShiftRegister({
  isAnode: true,
  pins: [2, 3, 4]
});

Shift Register Seven Segment Common Anode

Usage

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var register = new five.ShiftRegister({
    isAnode: true,
    pins: {
      data: 2,
      clock: 3,
      latch: 4,
      reset: 9,
    }
  });
  var number = 0;
  var decimal = 0;

  register.reset();

  // Display numbers 0-9, one at a time in a loop.
  // Shows just the number for a half second, then
  // the number + a decimal point for a half second.
  setInterval(function() {
    register.display(number + (decimal && "."));

    if (decimal) {
      number++;
    }

    if (number > 9) {
      number = 0;
    }

    decimal ^= 1;
  }, 500);
});

API

  • clear() Clear the register.

  • display(number) Display a number on a seven segment display.

    // Display a 1 on a single seven segment controlled
    // by the shift register.
    register.display(1);
    
  • display(string) Display a number on a seven segment display, optionally including the decimal point.

    // Display a 1 on a single seven segment controlled
    // by the shift register. The decimal point will also be lit
    register.display("1.");
    
    // Display a 1 on a single seven segment controlled
    // by the shift register. The decimal point will NOT be lit
    register.display("1");
    
  • reset() Reset the register.

  • send(B) Send an 8-bit byte value to the shift register.

  • send([B1, B2]) Send an array of 8-bit byte values to the shift register.

Events

ShiftRegister objects are output only and therefore do not emit any events.

Examples

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