Back to Johnny Five

Thermometer - Dual DS18B20

docs/temperature-dual-ds18b20.md

2.1.01.7 KB
Original Source
<!--remove-start-->

Thermometer - Dual DS18B20

<!--remove-end-->

Run this example from the command line with:

bash
node eg/temperature-dual-ds18b20.js
javascript
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

 

<!--remove-start-->

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.

<!--remove-end-->