CHIRIMEN Push button - ISOKS

Created Date: 2015-07-25/ updated date: 2018-03-13
    Owner & Collaborators
    License
    Summary
    CHIRIMENでプッシュボタンを扱う方法。

    Memo

    main.js(押すたびにオンオフ変更版)

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

    window.addEventListener('load', function (){
     
      Promise.all([
        navigator.setGpioPort(198,"out"),
        navigator.setGpioPort(199,"in")
      ]).then(ports=>{
        var ledPort = ports[0];
        var buttonPort = ports[1];
        var x;
       
        buttonPort.onchange = function(v){
          if(v == 0){
          x = x ? 0:1;
          }
          ledPort.write(x);
        }
      });

    }, false);

    Comments