Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

5.2.3 SHT30 のコードを読む

  • ターミナルウィンドウ右側のファイルマネージャで main-sht30.js を選択し、「表示」を実行してソースコードを開きます。
import { requestI2CAccess } from "node-web-i2c";
import SHT30 from "@chirimen/sht30";
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const i2cAccess = await requestI2CAccess();
const sht30 = new SHT30(i2cAccess.ports.get(1), 0x44);
await sht30.init();

while (true) {
  const { humidity, temperature } = await sht30.readData();
  console.log(
    [
      `Humidity: ${humidity.toFixed(2)}%`,
      `Temperature: ${temperature.toFixed(2)} degree`,
    ].join(", "),
  );

  await sleep(500);
}
import { requestI2CAccess } from "node-web-i2c";
import SHT30 from "@chirimen/sht30";