{"id":5346,"date":"2017-02-06T12:31:32","date_gmt":"2017-02-06T03:31:32","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=5346"},"modified":"2017-08-07T17:13:04","modified_gmt":"2017-08-07T08:13:04","slug":"reveal-js%e3%82%92chibibitmicrobit%e3%81%a7%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/microbit\/5346","title":{"rendered":"Reveal.js\u3092Micro:bit(chibi:bit)\u3067\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u3002"},"content":{"rendered":"<p>Reveal.js\u3067\u4f5c\u6210\u3057\u305f\u30b9\u30e9\u30a4\u30c9\u3092chibi:bit\u3067\u64cd\u4f5c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"550\" data-dnt=\"true\">\n<p lang=\"ja\" dir=\"ltr\">&quot;GitHub &#8211; shimizu\/microbit-ble-example&quot;  microbit(chibibit)\u3067\u30b9\u30e9\u30a4\u30c9\u64cd\u4f5c\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092github\u306b\u4e0a\u3052\u305f\u3002<a href=\"https:\/\/t.co\/KVBWXZmtnA\">https:\/\/t.co\/KVBWXZmtnA<\/a> <a href=\"https:\/\/t.co\/G8PpjhaXap\">pic.twitter.com\/G8PpjhaXap<\/a><\/p>\n<p>&mdash; \u6e05\u6c34\u6b63\u884c (@_shimizu) <a href=\"https:\/\/twitter.com\/_shimizu\/status\/826601653587423232?ref_src=twsrc%5Etfw\">February 1, 2017<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<h2>\u4ed5\u7d44\u307f<\/h2>\n<p>chibi:bit\u3068Mac\u3092BLE\u3067\u7e4b\u304e\u30dc\u30bf\u30f3\u64cd\u4f5c\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002\u305d\u308c\u3092websocket\u3092\u901a\u3058\u3066Reveal.js\u306b\u4f1d\u9054\u3059\u308b\u3053\u3068\u3067\u3001\u30b9\u30e9\u30a4\u30c9\u306e\u30da\u30fc\u30b8\u3081\u304f\u308a\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u4e0b\u8a18\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u30a2\u30c3\u30d7\u3057\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/shimizu\/microbit-ble-example\">shimizu\/microbit-ble-example: node.js\u3067microbit\u3092BLE\u3092\u4f7f\u3063\u3066\u64cd\u4f5c\u3059\u308b\u30b5\u30f3\u30d7\u30eb<\/a><\/p>\n<h2>node-bbc-microbit<\/h2>\n<p>node.js\u30e9\u30a4\u30d6\u30e9\u30ea\u300cnode-bbc-microbit\u300d\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001chibi:bit(micro:bit)\u3092BLE\u3067\u30d1\u30bd\u30b3\u30f3\u306b\u3064\u306a\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\nnode-bbc-microbit\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u306f\u3001README\u306b\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u305d\u3061\u3089\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/sandeepmistry\/node-bbc-microbit\">sandeepmistry\/node-bbc-microbit: Control a BBC micro:bit from Node.js using BLE<\/a><\/p>\n<h3>\u30dc\u30bf\u30f3\u64cd\u4f5c\u3092\u53d6\u5f97\u3059\u308b\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"lang:js decode:true \" title=\"\u30dc\u30bf\u30f3\u64cd\u4f5c\u53d6\u5f97\" >var BBCMicrobit = require('bbc-microbit')\r\nvar BUTTON_VALUE_MAPPER = ['Not Pressed', 'Pressed', 'Long Press'];\r\n\r\n\r\nconsole.log('chibi:bit\u3092\u691c\u7d22\u3057\u3066\u3044\u307e\u3059')\r\nBBCMicrobit.discover(function(microbit) {\r\n\tconsole.log('chibi:bit\u3092\u767a\u898b\u3057\u307e\u3057\u305f: id = %s, address = %s', microbit.id, microbit.address)\r\n\r\n\tmicrobit.on('disconnect', function() {\r\n\t\tconsole.log('\u30a8\u30e9\u30fc\uff01\uff1a\u63a5\u7d9a\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f')\r\n\t\tprocess.exit(0)\r\n\t})\r\n\r\n\tmicrobit.connectAndSetUp(function() {\r\n\t\tconsole.log('chibi:bit\u306b\u63a5\u7d9a\u3057\u307e\u3057\u305f')\r\n\t\r\n\t\tmicrobit.subscribeButtons(function() {\r\n\t\t\tconsole.log('\u30dc\u30bf\u30f3\u5165\u529b\u3092\u53d7\u4ed8\u4e2d')\r\n\t\t})\r\n\t})\r\n  \r\n  \r\n\tmicrobit.on('buttonAChange', function(value) {\r\n\t\tconsole.log('\uff21\u30dc\u30bf\u30f3: ', BUTTON_VALUE_MAPPER[value])\r\n\t})\r\n\r\n\tmicrobit.on('buttonBChange', function(value) {\r\n\t\tconsole.log('\uff22\u30dc\u30bf\u30f3: ', BUTTON_VALUE_MAPPER[value])\r\n\t})\r\n\r\n})<\/pre>\n<h3>\u30b9\u30e9\u30a4\u30c9\u64cd\u4f5c\u30b5\u30f3\u30d7\u30eb<\/h3>\n<p>Reveal.js\u3067\u4f5c\u6210\u3057\u305f\u30b9\u30e9\u30a4\u30c9\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306b\u3001web\u30b5\u30fc\u30d0\u30fc\u3068\u3057\u3066\u300cserve-static\u300d\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002websocket\u30b5\u30fc\u30d0\u30fc\u306f\u300csocket.io\u300d\u3092\u4f7f\u7528\u3002<br \/>\nBLE\u3067\u306f\u3001\u975e\u540c\u671f\u51e6\u7406\u304c\u3069\u3046\u3057\u3066\u3082\u591a\u304f\u306a\u308b\u306e\u3067promis\u3067\u307e\u3068\u3081\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:js decode:true \" title=\"sever.js\" >var BBCMicrobit = require('bbc-microbit')\r\nvar exec = require('child_process').exec\r\nvar http = require('http')\r\nvar finalhandler = require('finalhandler')\r\nvar serveStatic = require('serve-static')\r\nvar BUTTON_VALUE_MAPPER = ['Not Pressed', 'Pressed', 'Long Press'];\r\n\r\n\r\nconsole.log('chibi:bit\u3092\u691c\u7d22\u3057\u3066\u3044\u307e\u3059')\r\nvar discoverMcrobit = new Promise(function(resolve, reject){\r\n    BBCMicrobit.discover(function(microbit) {\r\n        console.log('\\tchibi:bit\u3092\u767a\u898b\u3057\u307e\u3057\u305f: id = %s, address = %s', microbit.id, microbit.address)\r\n        microbit.on('disconnect', function() {\r\n          console.log('\\t\u63a5\u7d9a\u30a8\u30e9\u30fc\uff01\uff1achibi:bit\u306b\u63a5\u7d9a\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f')\r\n          process.exit(0);\r\n        })\r\n    \r\n        resolve(microbit)\r\n    })    \r\n})\r\n\r\nvar subscribeButtons = function(microbit){\r\n    return new Promise(function(resolve, reject){\r\n        microbit.connectAndSetUp(function() {\r\n          console.log('\\t\u63a5\u7d9a\u3057\u307e\u3057\u305f')\r\n        \r\n            microbit.subscribeButtons(function() {\r\n                console.log('\\t\u30dc\u30bf\u30f3\u5165\u529b\u3092\u53d7\u4ed8\u4e2d');\r\n                resolve(microbit)\r\n            })\r\n        })\r\n    })    \r\n}\r\n\r\nvar onClickButtons = function(collection){\r\n\tvar microbit = collection.microbit\r\n\tvar socket = collection.socket\r\n\t\r\n\t\r\n    return new Promise(function(resolve, reject){\r\n        microbit.on('buttonAChange', function(value) {\r\n            console.log('\\ton -&gt; button A change: ', BUTTON_VALUE_MAPPER[value]);\r\n\t\t\tif (BUTTON_VALUE_MAPPER[value] == \"Pressed\")\r\n\t\t\t\tsocket.emit('greeting', {message: 'A button'})\t\r\n        })\r\n        \r\n        microbit.on('buttonBChange', function(value) {\r\n            console.log('\\ton -&gt; button B change: ', BUTTON_VALUE_MAPPER[value]);\r\n\t\t\tif (BUTTON_VALUE_MAPPER[value] == \"Pressed\")\r\n\t\t\t\tsocket.emit('greeting', {message: 'B button'})\r\n        })\r\n\t\t\r\n\t\tresolve(microbit)\r\n    })    \r\n}\r\n\r\nfunction runWebscoketServer(microbit) {\r\n    return new Promise(function(resolve, reject){\r\n\t\t\r\n\t\tvar io = require('socket.io').listen(8124);\r\n\t\texec(\"open http:\/\/localhost:8000\")\r\n\r\n\t\tio.sockets.on('connection', function(socket) {\r\n\t\t\tresolve({microbit:microbit, socket:socket})\r\n\t\t})  \t\t\r\n    })    \t\r\n}\r\n\r\n\r\n\/\/webserver \u8d77\u52d5\r\nvar serve = serveStatic(__dirname, {'index': ['index.html', 'index.htm']})\r\nvar server = http.createServer(function onRequest (req, res) {\r\n\tserve(req, res, finalhandler(req, res))\r\n})\r\nserver.listen(8000)\r\n\r\n\r\ndiscoverMcrobit.then(subscribeButtons).then(runWebscoketServer).then(onClickButtons)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Reveal.js\u3067\u4f5c\u6210\u3057\u305f\u30b9\u30e9\u30a4\u30c9\u3092chibi:&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5347,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-5346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microbit","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=5346"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5346\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/5347"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=5346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=5346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=5346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}