{"action":"created","issue":{"url":"https://api.github.com/repos/rwaldron/spark-io/issues/63","labels_url":"https://api.github.com/repos/rwaldron/spark-io/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/rwaldron/spark-io/issues/63/comments","events_url":"https://api.github.com/repos/rwaldron/spark-io/issues/63/events","html_url":"https://github.com/rwaldron/spark-io/issues/63","id":99762632,"number":63,"title":"new five.Button ( TypeError: pin.replace is not a function )","user":{"login":"chrisbuttery","id":121675,"avatar_url":"https://avatars.githubusercontent.com/u/121675?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisbuttery","html_url":"https://github.com/chrisbuttery","followers_url":"https://api.github.com/users/chrisbuttery/followers","following_url":"https://api.github.com/users/chrisbuttery/following{/other_user}","gists_url":"https://api.github.com/users/chrisbuttery/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisbuttery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisbuttery/subscriptions","organizations_url":"https://api.github.com/users/chrisbuttery/orgs","repos_url":"https://api.github.com/users/chrisbuttery/repos","events_url":"https://api.github.com/users/chrisbuttery/events{/privacy}","received_events_url":"https://api.github.com/users/chrisbuttery/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-08T02:43:25Z","updated_at":"2015-08-08T23:43:37Z","closed_at":"2015-08-08T23:43:13Z","body":"Hi folks, \r\n\r\nI’ve come across an error when adding a `new five.Button()` to spark-io board.\r\n\r\nI’ve looked through the examples in `/eg`, but there doesn’t seem to be one using a button,\r\nso forgive me if Im missing something about buttons and spark-io - I’m kind of new to this.\r\n\r\n```js\r\n\"devDependencies\": {\r\n  \"johnny-five\": \"^0.8.85\",\r\n  \"spark-io\": \"^0.6.1\"\r\n}\r\n```\r\nHere’s the script\r\n\r\n```js\r\nvar five = require('johnny-five')\r\nvar Spark = require('spark-io')\r\n\r\nvar board = new five.Board({\r\n  io: new Spark({\r\n    token: process.env.SPARK_TOKEN,\r\n    deviceId: process.env.SPARK_DEVICE_ID\r\n  })\r\n})\r\n\r\nboard.on('ready', function() {\r\n  var button = new five.Button('D3') // Booo!\r\n\r\n  button.on('down', function() {\r\n    console.log('down')\r\n  })\r\n})\r\n```\r\n\r\nHere’s the error:\r\n\r\n```bash\r\nnodebots % node button.js\r\n1438999226193 Device(s) spark-io  \r\n1438999227426 Connected spark-io  \r\n1438999227601 Repl Initialized  \r\n>> /Users/chrisbuttery/Web/nodebots/node_modules/spark-io/lib/spark.js:318\r\n  pinInt = (pin.replace(/A|D/, \"\") | 0) + offset;\r\n                ^\r\nTypeError: pin.replace is not a function\r\n    at Spark.pinMode (/Users/chrisbuttery/Web/nodebots/node_modules/spark-io/lib/spark.js:318:17)\r\n    at Button.Controllers.DEFAULT.initialize.value (/Users/chrisbuttery/Web/nodebots/node_modules/johnny-five/lib/button.js:29:17)\r\n    at new Button (/Users/chrisbuttery/Web/nodebots/node_modules/johnny-five/lib/button.js:189:10)\r\n    at Board.<anonymous> (/Users/chrisbuttery/Web/nodebots/game-buzzer.js:12:16)\r\n    at emitNone (events.js:67:13)\r\n    at Board.emit (events.js:163:7)\r\n    at doNTCallback0 (node.js:415:9)\r\n    at process._tickDomainCallback (node.js:385:13)\r\n```\r\n\r\nSo here are the `opts` when `johnny-five` calls it’s button initialisation:\r\n\r\nhttps://github.com/rwaldron/johnny-five/blob/master/lib/button.js#L187\r\n\r\n```js\r\nif (typeof this.initialize === \"function\") {\r\n  this.initialize(opts, function(data) {\r\n\r\n    // opts = Options {pin: \"D3\", pinValue: \"D3\"}\r\n  }\r\n}\r\n```\r\n\r\nHere are the opts when the button is initialised:\r\n\r\nhttps://github.com/rwaldron/johnny-five/blob/master/lib/button.js#L21\r\n\r\n```js\r\nvar Controllers = {\r\n  DEFAULT: {\r\n    initialize: {\r\n      value: function(opts, dataHandler) {\r\n\r\n        if (Pins.isFirmata(this) && typeof opts.pinValue === \"string\" && opts.pinValue[0] === \"A\") {\r\n          opts.pinValue = this.io.analogPins[+opts.pinValue.slice(1)];\r\n        }\r\n\r\n        this.pin = +opts.pinValue;\r\n\r\n        // opts = Options {pin: \"D3\", pinValue: \"D3\"}\r\n        // this = Button {board: Board, io: Spark, id: null, pin: NaN, holdtime: 500…}\r\n        // this.board.io.name = \"spark-io\"\r\n        // 'Pins.isFirmata(this) = false\r\n        // opts.pinValue = \"D3\"\r\n        // opts.pinValue[0] === \"A\" = false\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n… and the `spark-io` throws an error here:\r\n\r\nhttps://github.com/rwaldron/spark-io/blob/master/lib/spark.js#L325\r\n\r\n```js\r\npinInt = (pin.replace(/A|D/, \"\") | 0) + offset;\r\n\r\n// pin = NaN\r\n```"},"comment":{"url":"https://api.github.com/repos/rwaldron/spark-io/issues/comments/129070978","html_url":"https://github.com/rwaldron/spark-io/issues/63#issuecomment-129070978","issue_url":"https://api.github.com/repos/rwaldron/spark-io/issues/63","id":129070978,"user":{"login":"rwaldron","id":27985,"avatar_url":"https://avatars.githubusercontent.com/u/27985?v=3","gravatar_id":"","url":"https://api.github.com/users/rwaldron","html_url":"https://github.com/rwaldron","followers_url":"https://api.github.com/users/rwaldron/followers","following_url":"https://api.github.com/users/rwaldron/following{/other_user}","gists_url":"https://api.github.com/users/rwaldron/gists{/gist_id}","starred_url":"https://api.github.com/users/rwaldron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwaldron/subscriptions","organizations_url":"https://api.github.com/users/rwaldron/orgs","repos_url":"https://api.github.com/users/rwaldron/repos","events_url":"https://api.github.com/users/rwaldron/events{/privacy}","received_events_url":"https://api.github.com/users/rwaldron/received_events","type":"User","site_admin":false},"created_at":"2015-08-08T23:43:37Z","updated_at":"2015-08-08T23:43:37Z","body":"new version of Johnny-Five will push out later this evening."}}