{"id":8819,"date":"2018-04-07T02:43:44","date_gmt":"2018-04-06T17:43:44","guid":{"rendered":"http:\/\/leavebehind.iobb.net\/wordpress\/?p=8819"},"modified":"2018-07-28T16:14:51","modified_gmt":"2018-07-28T07:14:51","slug":"opmayawitharduino","status":"publish","type":"post","link":"http:\/\/leavebehind.mydns.jp\/wordpress\/2018\/04\/07\/opmayawitharduino\/","title":{"rendered":"Arduino\u3067Maya\u3092\u64cd\u4f5c\u3059\u308b"},"content":{"rendered":"<p>\u7c21\u5358\u306a\u30c8\u30b3\u30ed\u304b\u3089\u3001\u30dc\u30bf\u30f3\u4ed8\u304d\u30ed\u30fc\u30bf\u30ea\u30fc\u30a8\u30f3\u30b3\u30fc\u30c0\u3067\u30bf\u30a4\u30e0\u30b9\u30e9\u30a4\u30c0\u3092\u30b9\u30af\u30e9\u30d6\u3001\u30dc\u30bf\u30f3\u3067\u518d\u751f\u3001\u505c\u6b62\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8827 size-large\" src=\"http:\/\/leavebehind.iobb.net\/wordpress\/wp-content\/uploads\/2018\/04\/photo2018-04-04_-18-24-56-1024x886.jpg\" alt=\"\" width=\"750\" height=\"649\" srcset=\"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-content\/uploads\/2018\/04\/photo2018-04-04_-18-24-56.jpg 1024w, http:\/\/leavebehind.mydns.jp\/wordpress\/wp-content\/uploads\/2018\/04\/photo2018-04-04_-18-24-56-300x260.jpg 300w, http:\/\/leavebehind.mydns.jp\/wordpress\/wp-content\/uploads\/2018\/04\/photo2018-04-04_-18-24-56-768x665.jpg 768w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>\u9593\u306bProcessing\u3067\u4f5c\u6210\u3057\u305f\u30a2\u30d7\u30ea\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u304c\u3001Maya\u3078<a href=\"https:\/\/pypi.python.org\/pypi\/pyserial\">pyserial<\/a>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066Arduino\u3068Maya\u3092\u76f4\u63a5\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3067\u3064\u306a\u3052\u308b\u4e8b\u3082\u3067\u304d\u308b\u304b\u3082\u3002<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8820 size-full\" src=\"http:\/\/leavebehind.iobb.net\/wordpress\/wp-content\/uploads\/2018\/04\/ArduinoToMaya.jpg\" alt=\"\" width=\"720\" height=\"241\" srcset=\"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-content\/uploads\/2018\/04\/ArduinoToMaya.jpg 720w, http:\/\/leavebehind.mydns.jp\/wordpress\/wp-content\/uploads\/2018\/04\/ArduinoToMaya-300x100.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><!--more--><\/p>\n<p>\u30ed\u30fc\u30bf\u30ea\u30fc\u30a8\u30f3\u30b3\u30fc\u30c0\u304c\u8fd4\u3059\u30b0\u30ec\u30a4\u30b3\u30fc\u30c9\u306e\u6271\u3044\u304c\u3042\u3063\u3066\u308b\u304b\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u4ee5\u4e0b\u304cArduino IDE\u306e\u30b3\u30fc\u30c9\u3002<\/p>\n<pre class=\"lang:c decode:true\" title=\"Arduino\">const int ENCA_PIN PROGMEM = 10;\nconst int ENCB_PIN PROGMEM =  9;\nconst int BTN_PIN  PROGMEM =  8;\n\nint lastBtn = HIGH;\nint lastu = -1;\nint lastv = -1;\n\nint count = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(ENCA_PIN, INPUT);\n  pinMode(ENCB_PIN, INPUT);\n  pinMode(BTN_PIN, INPUT_PULLUP);\n}\n\nvoid loop() {\n  int u = digitalRead(ENCA_PIN);\n  int v = digitalRead(ENCB_PIN);\n\n  if((lastu != u) || (lastv != v)){\n    if((u == 1) &amp;&amp; (v == 1)){\n      if(lastu == 1){\n        count ++;\n        sendData(\"r\",count);\n        \/\/Serial.println(\"plus\");\n      }\n  \n      if(lastu == 0){\n        count --;\n        sendData(\"r\",count);\n      }\n    }\n  }\n\n  int btn = digitalRead(BTN_PIN);\n  if((btn == LOW) &amp;&amp; (btn != lastBtn)){\n    sendData(\"c\",0);\n    delay(100);\n  }\n  lastBtn = btn;\n  lastu = u;\n  lastv = v;\n}\n\nvoid sendData(char *id,int value){\n  Serial.print(id);\n  Serial.print(\",\");\n  Serial.println(value);\n}\n<\/pre>\n<p><a href=\"https:\/\/www.amazon.co.jp\/gp\/product\/B014VUOP7S\/ref=as_li_tl?ie=UTF8&amp;camp=247&amp;creative=1211&amp;creativeASIN=B014VUOP7S&amp;linkCode=as2&amp;tag=gofariobbnet-22&amp;linkId=b43d457c24a81f60c7014e6f88b175c1\" target=\"_blank\" rel=\"noopener\">\u30ed\u30fc\u30bf\u30ea\u30fc\u30a8\u30f3\u30b3\u30fc\u30c0<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"\/\/ir-jp.amazon-adsystem.com\/e\/ir?t=gofariobbnet-22&amp;l=am2&amp;o=9&amp;a=B014VUOP7S\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/>\u3068Arduino Uno R3\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7d50\u7dda\u3002<\/p>\n<ul>\n<li>CLK\u3068Digital10<\/li>\n<li>DT\u3068Digital9<\/li>\n<li>SW\u3068Digital8<\/li>\n<li>+\u30685V<\/li>\n<li>GND\u3068GND<\/li>\n<\/ul>\n<p>\u6b21\u306bProcessing\u3001Maya\u3078\u76f4\u63a5mel\u30b3\u30de\u30f3\u30c9\u3092\u9001\u3063\u3066\u3044\u307e\u3059\u3001Processing\u4e0a\u306b\u30cf\u30fc\u30c9\u30b3\u30fc\u30c9\u3059\u308b\u3088\u308a\u3001Maya\u5074\u3067\u30b3\u30de\u30f3\u30c9\u3092\u6301\u3063\u3066\u304a\u304f\u65b9\u304c\u826f\u3044\u3068\u306f\u601d\u3044\u307e\u3059\u304c\u3002<\/p>\n<pre class=\"lang:java decode:true\" title=\"Processing\">import processing.net.*;\nimport processing.serial.*;\n\nSerial myport;\nClient myclient;\nint value = 0;\nint lastValue = 0;\n\nvoid setup(){\n  size(512,128);\n  printArray(Serial.list());\n  myport = new Serial(this, Serial.list()[1], 115200);\n  myport.bufferUntil('\\n');\n  myclient = new Client(this,\"127.0.0.1\", 7001);\n  \n  noLoop();\n}\n\nvoid draw() {\n  background(0);\n  textSize(32);\n  text(\"Maya w\/Arduino\", 10, 30);\n}\n\nvoid stop(){\n  myport.stop();\n  myclient.stop();\n}\n\nvoid serialEvent(Serial myport){\n  String mystr = myport.readStringUntil('\\n');\n  String data[] = split(trim(mystr), ',');\n  \/\/printArray(data);\n\n  if(data[0].equals(\"r\")){\n    value = int(data[1]);\n    if(lastValue - value &lt; 0){\n      myclient.write(\"currentTime (`currentTime -q`+1);\");\n    }else{\n      myclient.write(\"currentTime (`currentTime -q`-1);\");\n    }\n    lastValue = value;\n  }\n  \n  if(data[0].equals(\"c\")){\n    myclient.write(\"if(`play -q -st`){play -st false;}else{play -st true;}\");\n  }\n}<\/pre>\n<p>\u5f8c\u306fMaya\u3092\u8d77\u52d5\u3057\u3066\u4ee5\u4e0b\u3092\u5b9f\u884c\u3057mel\u30b3\u30de\u30f3\u30c9\u7528\u306b7001\u756a\u30dd\u30fc\u30c8\u3092\u958b\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:python decode:true \" title=\"Maya\u3067Mel\u30b3\u30de\u30f3\u30c9\u53d7\u4fe1\u7528\u306e\u30dd\u30fc\u30c8\u3092\u958b\u304f\">import maya.cmds as cmds\ntry:\n    cmds.commandPort(name=\":7001\", close=True)\nexcept:\n    cmds.warning('Could not close port 7001 (maybe it is not opened yet...)')\n\ncmds.commandPort(name=\":7001\", sourceType=\"mel\")<\/pre>\n<p>Arduino IDE\u3082Processing\u3082\u63a5\u7d9a\u304c\u51fa\u6765\u306a\u3044\u5834\u5408\u306e\u51e6\u7406\u3092\u7701\u3044\u3066\u3044\u307e\u3059\u3002Arduino\u3001Maya(\u30dd\u30fc\u30c8\u3092\u958b\u3051\u308b)\u3001Processing\u306e\u9806\u306b\u8d77\u52d5\u3057\u3066\u3072\u3068\u307e\u305a\u51fa\u6765\u4e0a\u304c\u308a\uff5e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c21\u5358\u306a\u30c8\u30b3\u30ed\u304b\u3089\u3001\u30dc\u30bf\u30f3\u4ed8\u304d\u30ed\u30fc\u30bf\u30ea\u30fc\u30a8\u30f3\u30b3\u30fc\u30c0\u3067\u30bf\u30a4\u30e0\u30b9\u30e9\u30a4\u30c0\u3092\u30b9\u30af\u30e9\u30d6\u3001\u30dc\u30bf\u30f3\u3067\u518d\u751f\u3001\u505c\u6b62\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u9593\u306bProcessing\u3067\u4f5c\u6210\u3057\u305f\u30a2\u30d7\u30ea\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u304c\u3001Maya\u3078pyserial\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Arduino\u3067Maya\u3092\u64cd\u4f5c\u3059\u308b","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16],"tags":[43,175,226],"class_list":["post-8819","post","type-post","status-publish","format-standard","hentry","category-toys","tag-arduino","tag-maya","tag-processing"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p8YSE4-2if","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/posts\/8819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/comments?post=8819"}],"version-history":[{"count":13,"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/posts\/8819\/revisions"}],"predecessor-version":[{"id":8834,"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/posts\/8819\/revisions\/8834"}],"wp:attachment":[{"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/media?parent=8819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/categories?post=8819"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leavebehind.mydns.jp\/wordpress\/wp-json\/wp\/v2\/tags?post=8819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}