'use strict';

window.addEventListener('load', function (){
  var head = document.querySelector('#head');
  
  // WebI2C Initialized
  navigator.requestI2CAccess()
    .then(function(i2cAccess){
      return i2cAccess.ports;
    }).then(function(ports){
      return ports.get(0);
    }).then(function(port){
      var pcs9685 = new PCA9685(port,0x40);
      var angle = 90;
      console.log("angle"+angle);
      //servo setting for sg90
      pcs9685.init(0.00050,0.00240,180).then(function(){
        console.log("init");
        setInterval(function(){
          angle = (angle<=10) ? 170 : 10;
          console.log("angle"+angle);
          pcs9685.setServo(0,angle).then(function(){
            console.log('value:', angle);
            head.innerHTML = angle;
          });
        },1000);
      });
      
    }).catch(e=> console.error('error', e));
}, false);
@@ -194,22 +194,26 @@
 %7B%0A      
-return
+var port =
  i2cAcce
@@ -224,93 +224,16 @@
 orts
-;%0A    %7D).then(function(ports)%7B%0A      return ports.get(0);%0A    %7D).then(function(port)%7B
+.get(0);
 %0A   

update servo