{"action":"created","issue":{"url":"https://api.github.com/repos/MrYsLab/PyMata/issues/18","labels_url":"https://api.github.com/repos/MrYsLab/PyMata/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/MrYsLab/PyMata/issues/18/comments","events_url":"https://api.github.com/repos/MrYsLab/PyMata/issues/18/events","html_url":"https://github.com/MrYsLab/PyMata/issues/18","id":97560348,"number":18,"title":"Extended comments on example for callback_ping_config_and_read","user":{"login":"dkurok","id":12998706,"avatar_url":"https://avatars.githubusercontent.com/u/12998706?v=3","gravatar_id":"","url":"https://api.github.com/users/dkurok","html_url":"https://github.com/dkurok","followers_url":"https://api.github.com/users/dkurok/followers","following_url":"https://api.github.com/users/dkurok/following{/other_user}","gists_url":"https://api.github.com/users/dkurok/gists{/gist_id}","starred_url":"https://api.github.com/users/dkurok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkurok/subscriptions","organizations_url":"https://api.github.com/users/dkurok/orgs","repos_url":"https://api.github.com/users/dkurok/repos","events_url":"https://api.github.com/users/dkurok/events{/privacy}","received_events_url":"https://api.github.com/users/dkurok/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-27T21:40:40Z","updated_at":"2015-07-27T23:18:24Z","closed_at":"2015-07-27T23:18:24Z","body":"Hello,\r\nI also tested the callback-example for Sonar and did some extended comments and also mentioned that the signal_handler doe Ctrl-C will not work very well.\r\nIf you like, you can replace it in your example or add it as a new one.\r\nsorry for not branching/pull request - not so clear to me at the moment (new to git)\r\n```phyton\r\n#!/usr/bin/env python\r\n\"\"\"\r\nCopyright (c) 2013-2015 Alan Yorinks All rights reserved.\r\n\r\nThis program is free software; you can redistribute it and/or\r\nmodify it under the terms of the GNU  General Public\r\nLicense as published by the Free Software Foundation; either\r\nversion 3 of the License, or (at your option) any later version.\r\n\r\nThis library is distributed in the hope that it will be useful,\r\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\r\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n General Public License for more details.\r\n\r\nYou should have received a copy of the GNU  General Public\r\nLicense along with this library; if not, write to the Free Software\r\nFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r\n\"\"\"\r\nimport time\r\nimport sys\r\nimport signal\r\n\r\nfrom PyMata.pymata import PyMata\r\n\r\n# Ping callback function\r\ndef cb_ping(data):\r\n    # will always print 11, because first element in data is firmata.SONAR = 0xb = 11\r\n    #print(data[0])\r\n    # will print 12 in this case; it's the pin-number of the attached sonar-device;\r\n    # so here is the place to decide which device has called the callback (if you want to handle multiple devices with one callback)\r\n    # like: if (data[1] == Pin_device_0): ...\r\n    print(data[1])\r\n    print(str(data[2]) + ' centimeters')\r\n\r\n# Create a PyMata instance\r\nboard = PyMata(\"COM7\", verbose=True)\r\n\r\ndef signal_handler(sig, frame):\r\n    print('You pressed Ctrl+C!!!!')\r\n    if board is not None:\r\n        board.reset()\r\n        board.close()\r\n    sys.exit(0)\r\n\r\nsignal.signal(signal.SIGINT, signal_handler)\r\n\r\n# Configure pin 12 for SONAR module (see png)\r\n# every 100 ms it will trigger the sonar to meassure the distance and call the callback, if the value has changed compared to previous meassure\r\n# AND the distance is <=100\r\n board.sonar_config(12, 12, cb_ping, 100, 100)\r\n# if you just do:\r\n#board.sonar_config(12 , 12, cb_ping)\r\n# it will use 50ms as the ping interval and 200 centimeters (which is also the maximum)\r\n\r\n# after 30 seconds stop; sleep will sleep the main-thread; so Ctrl-C will not work (at least under Windows) in this time\r\n# so in this example you may also take out the signal_handler if you like; it will work, but directly \r\n# between the following sleep and the board.close\r\ntime.sleep(30)\r\nboard.close()\r\n```"},"comment":{"url":"https://api.github.com/repos/MrYsLab/PyMata/issues/comments/125376659","html_url":"https://github.com/MrYsLab/PyMata/issues/18#issuecomment-125376659","issue_url":"https://api.github.com/repos/MrYsLab/PyMata/issues/18","id":125376659,"user":{"login":"MrYsLab","id":5189838,"avatar_url":"https://avatars.githubusercontent.com/u/5189838?v=3","gravatar_id":"","url":"https://api.github.com/users/MrYsLab","html_url":"https://github.com/MrYsLab","followers_url":"https://api.github.com/users/MrYsLab/followers","following_url":"https://api.github.com/users/MrYsLab/following{/other_user}","gists_url":"https://api.github.com/users/MrYsLab/gists{/gist_id}","starred_url":"https://api.github.com/users/MrYsLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrYsLab/subscriptions","organizations_url":"https://api.github.com/users/MrYsLab/orgs","repos_url":"https://api.github.com/users/MrYsLab/repos","events_url":"https://api.github.com/users/MrYsLab/events{/privacy}","received_events_url":"https://api.github.com/users/MrYsLab/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T23:18:24Z","updated_at":"2015-07-27T23:18:24Z","body":"Thanks for your input. I modified the examples. Please let me know if you see any other issues."}}