Using a MUXSHIELD2 Expander as a Virtual Board. Displays value of potentiometers in console graph. (npm install barcli)

Breadboard for "Expander - MUXSHIELD2, Analog Sensors"

expander-MUXSHIELD2-analog-read.png

Fritzing diagram: expander-MUXSHIELD2-analog-read.fzz

 

Run this example from the command line with:

node eg/expander-MUXSHIELD2-analog-read.js
const Barcli = require("barcli");
const { Board, Expander, Sensor } = require("johnny-five");
const board = new Board({
  repl: false,
  debug: false
});

board.on("ready", () => {
  const range = [0, 1023];
  const bars = {
    a: new Barcli({ label: "IO1-15", range }),
    b: new Barcli({ label: "IO2-15", range }),
  };

  const virtual = new Board.Virtual(
    new Expander("MUXSHIELD2")
  );

  const a = new Sensor({
    pin: "IO1-15",
    board: virtual
  });

  a.on("change", () => {
    bars.a.update(a.value);
  });

  const b = new Sensor({
    pin: "IO2-15",
    board: virtual
  });

  b.on("change", () => {
    bars.b.update(b.value);
  });
});

 

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