Skip to content

Latest commit

 

History

History
82 lines (51 loc) · 1.71 KB

temperature-dual-ds18b20.md

File metadata and controls

82 lines (51 loc) · 1.71 KB

Thermometer - Dual DS18B20

Run this example from the command line with:

node eg/temperature-dual-ds18b20.js
const { Board, Thermometer } = require("johnny-five");
const board = new Board();

const controller = "DS18B20";

board.on("ready", () => {
  // This requires OneWire support using the ConfigurableFirmata
  const thermometerA = new Thermometer({
    controller,
    pin: 2,
    address: 0x687f1fe
  });

  const thermometerB = new Thermometer({
    controller,
    pin: 2,
    address: 0x6893a41
  });

  thermometerA.on("change", () => {
    const {address, celsius, fahrenheit, kelvin} = thermometerA;
    console.log(`Thermometer A at address: 0x${address.toString(16)}`);
    console.log("  celsius      : ", celsius);
    console.log("  fahrenheit   : ", fahrenheit);
    console.log("  kelvin       : ", kelvin);
    console.log("--------------------------------------");
  });

  thermometerB.on("change", () => {
    const {address, celsius, fahrenheit, kelvin} = thermometerB;
    console.log(`Thermometer B at address: 0x${address.toString(16)}`);
    console.log("  celsius      : ", celsius);
    console.log("  fahrenheit   : ", fahrenheit);
    console.log("  kelvin       : ", kelvin);
    console.log("--------------------------------------");
  });
});

Additional Notes

 

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.