Skip to content

Latest commit

 

History

History
90 lines (52 loc) · 1.51 KB

expander-MUXSHIELD2-analog-read.md

File metadata and controls

90 lines (52 loc) · 1.51 KB

Expander - MUXSHIELD2, Analog Sensors

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

Breadboard for "Expander - MUXSHIELD2, Analog Sensors"

docs/breadboard/expander-MUXSHIELD2-analog-read.png

Fritzing diagram: docs/breadboard/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);
  });
});

 

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.