CHIRIMEN I2C sensor

Created Date: 2015-07-25/ updated date: 2018-03-13
    Owner & Collaborators
    License
    Summary
    CHIRIMENでI2Cセンサを扱う方法。

    Memo

    main.js(温度)

    posted by Yamato-Ikeda on November 20, 2015
    'use strict';

    window.addEventListener('load', function (){

      navigator.requestI2CAccess().then(     /*初期化*/
        function(i2cAccess) {
          //open i2c-0 port
          var port = i2cAccess.open(0);
         
          setInterval(function(){
            //read temperature sensor
            ADT7410.read(port,0x48).then(value=>{     
              console.log(value);                                     /*センサー温度の取得*/
              document.getElementById("debug").innerHTML = value;    /*値の表示*/
            });
          },1000);
         
        },
        function(error) {
          console.log(error.message);
        }
      );
    }, false);

    Comments