Ad
Polymer({
    is: "pedal-assist",
    properties:{
      ppc:{
        type:Number,
        value:30,
      },
      gap:{
        type:Number,
        computed:"getGap(lPedel,rPedel)",
      },
      cycle:{
        type:Number,
        value:.5,
      },
    },
    left: function(undefined){
      this.lPedel = performance.now()

    },
    right: function(undefined){
      this.rPedel = performance.now()
    },
    getGap: function(lPedel,rPedel){
      var newGap = Math.sqrt((lPedel - rPedel) * (lPedel - rPedel))

      var r1 = this.gapOld / this.gap
      var r2 = this.gap / newGap
      console.log(r1,r2,newGap)
      if (r1 < 1.2 && r1 > .8 && r2 < 1.2 && r2 > .8) {
       this.runMotor(this.cycle,this.ppc,this.gap)
      }
      this.gapOld = this.gap
      return newGap
    },
    runMotor: function(cycle,ppc,time){
      var n= Math.floor(ppc*cycle)
      for (var i=1;i<n;i++) {
        setTimeout(function(that){
          if (that.black == 0) {
            that.set("black", 12)
            that.yellow = 0
            that.red = -12
          } else if (that.yellow == 0) {
            that.black = -12 
            that.yellow = 12
            that.red = 0
          } else if (that.red == 0) {
            that.black = 0 
            that.yellow = -12
            that.red = 12
          } 
        }, (time*cycle)*(i/n),this)

          console.log((time*cycle)*(i/n))
      }
      setTimeout(function(that){
        that.black = 0 
        that.yellow = 0
        that.red = 0
      }, (time*cycle)+10,this)
    },
  })