{"action":"closed","issue":{"url":"https://api.github.com/repos/101100/pca9685/issues/12","repository_url":"https://api.github.com/repos/101100/pca9685","labels_url":"https://api.github.com/repos/101100/pca9685/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/101100/pca9685/issues/12/comments","events_url":"https://api.github.com/repos/101100/pca9685/issues/12/events","html_url":"https://github.com/101100/pca9685/issues/12","id":190575944,"number":12,"title":"when two servos given simultaneous instructions, madness ensues","user":{"login":"kaeverens","id":2878523,"avatar_url":"https://avatars.githubusercontent.com/u/2878523?v=3","gravatar_id":"","url":"https://api.github.com/users/kaeverens","html_url":"https://github.com/kaeverens","followers_url":"https://api.github.com/users/kaeverens/followers","following_url":"https://api.github.com/users/kaeverens/following{/other_user}","gists_url":"https://api.github.com/users/kaeverens/gists{/gist_id}","starred_url":"https://api.github.com/users/kaeverens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaeverens/subscriptions","organizations_url":"https://api.github.com/users/kaeverens/orgs","repos_url":"https://api.github.com/users/kaeverens/repos","events_url":"https://api.github.com/users/kaeverens/events{/privacy}","received_events_url":"https://api.github.com/users/kaeverens/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-11-20T18:57:44Z","updated_at":"2016-11-22T20:47:28Z","closed_at":"2016-11-22T20:47:28Z","body":"my setup:\r\nservo on channel 0, controls a turret on a model tank\r\nservo on channel 8, controls the elevation of the cannon\r\n\r\nWhen I run the below code with staggered timeout offsets (offset1=2000, offset2=4000), it all works perfectly. But if I run with the /same/ offsets (4000 for both, for example), the servos appear to lose track of what they were doing.\r\n\r\nI'm not familiar with TypeScript, so am not certain I'll find anything in your code, but what it /appears/ to be is a variable from one servo's controller has been set with global scope and is being referenced by the other servo's controller by accident.\r\n\r\n```\r\n  pca9685 = new Pca9685Driver({\r\n    i2c: i2cBus.openSync(1),\r\n    address: 0x40,\r\n    frequency: 50,\r\n    debug: true\r\n  }, function() {\r\n    console.log(\"Initialization done\"); \r\n  });\r\n  function laserTurretBase(deg) {\r\n    var servoNumber=0;\r\n    if (deg<0 || deg>180) {\r\n      return;\r\n    }\r\n    pca9685.setPulseLength(servoNumber, 1500+Math.ceil((deg-90)/180*1499));\r\n    clearTimeout(timers.laserTurretBase);\r\n    timers.laserTurretBase=setTimeout(function() {\r\n      pca9685.setPulseRange(servoNumber, 0, -1);\r\n    }, 3000);\r\n  } \r\n  function laserTurretElevation(deg) {\r\n    var servoNumber=8;\r\n    if (deg<0 || deg>180) {\r\n      return;\r\n    }\r\n    pca9685.setPulseLength(servoNumber, 1500+Math.ceil((deg-90)/180*1499));\r\n    clearTimeout(timers.laserTurretElevation);\r\n    timers.laserTurretElevation=setTimeout(function() {\r\n      pca9685.setPulseRange(servoNumber, 0, -1);\r\n    }, 3000);\r\n  }\r\n  laserTurretBase(90);\r\n  laserTurretElevation(90);\r\n  var offset1=4000, offset2=4000;\r\n  setTimeout(function() {\r\n    laserTurretElevation(45);\r\n    setTimeout(function() {\r\n      laserTurretElevation(135);\r\n        setTimeout(function() {\r\n          laserTurretElevation(90);\r\n        }, 4000);\r\n    }, 4000);\r\n  }, offset1);\r\n  setTimeout(function() {\r\n    laserTurretBase(45);\r\n    setTimeout(function() {\r\n      laserTurretBase(135);\r\n        setTimeout(function() {\r\n          laserTurretBase(90);\r\n        }, 4000);\r\n    }, 4000);\r\n  }, offset2);\r\n```\r\n"}}
{"actor":{"display_login":"kaeverens"}}