{"id":1584,"date":"2022-08-27T14:43:34","date_gmt":"2022-08-27T05:43:34","guid":{"rendered":"https:\/\/machiaworx.net\/?p=1584"},"modified":"2022-09-07T14:29:14","modified_gmt":"2022-09-07T05:29:14","slug":"%e3%83%8f%e3%83%bc%e3%83%89%e3%82%b7%e3%83%bc%e3%82%b1%e3%83%b3%e3%82%b5%e9%96%8b%e7%99%ba%e3%80%82","status":"publish","type":"post","link":"https:\/\/machiaworx.net\/?p=1584","title":{"rendered":"\u30cf\u30fc\u30c9\u30b7\u30fc\u30b1\u30f3\u30b5\u958b\u767a\u3002\uff08\u305d\u306e\uff11\u30fb\u30d7\u30ed\u30b0\u30e9\u30e0\u691c\u8a3c\uff09"},"content":{"rendered":"<h3>\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u30b7\u30fc\u30b1\u30f3\u30b5\u958b\u767a<\/h3>\n<p>\u4e00\u5ea6\u30ad\u30fc\u30dc\u30fc\u30c9\u3092\u81ea\u4f5c\u59cb\u3081\u305f\u3068\u304d\u306b\u8a66\u3057\u306b\u65e2\u5b58\u306e\u30ad\u30fc\u30dc\u30fc\u30c9\u306e\u30d5\u30a1\u30fc\u30e0\u3092\u6539\u9020\u3057\u3066\u3001<br \/>\n\u30b7\u30fc\u30b1\u30f3\u30b5\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u3001\u305d\u308d\u305d\u308d\u57fa\u677f\u304b\u3089\u81ea\u4f5c\u3067\u3082\u554f\u984c\u306a\u304b\u308d\u3046\u3068\u8003\u3048\u3066\u3001\u6628\u65e5\u306f\u57fa\u677f\u306e\u8a2d\u8a08\u3092\u884c\u3044\u3001<br \/>\n\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u52d5\u4f5c\u691c\u8a3c\u3059\u3079\u304f\u8272\u3005\u66f8\u3044\u3066\u307e\u3057\u305f\u3002<\/p>\n<h3>CircuitPython\u306e\u5229\u7528\u306f\u4e2d\u6b62\u3002<\/h3>\n<p>\u4e0a\u8a18\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u3042\u307e\u308a\u306b\u51e6\u7406\u901f\u5ea6\u304c\u9045\u3044\u3053\u3068<\/li>\n<li>\u5185\u90e8\u3067\u51fa\u529b\u306e\u9045\u5ef6\u304c\u767a\u751f\u3057\u3066\u6b63\u78ba\u306a\u6642\u9593\u304c\u53d6\u308c\u305d\u3046\u3082\u306a\u3044<\/li>\n<li>\u5185\u90e8\u306e\u51e6\u7406\u304c\u4e00\u90e8\u602a\u3057\u3044\u90e8\u5206\u304c\u3042\u308b<\/li>\n<\/ul>\n<p>1\u756a\u76ee\u3060\u3051\u3067\u3042\u308c\u3070\u554f\u984c\u306a\u3044\u306e\u3067\u3059\u304c\u30012\u30fb3\u756a\u3081\u304c\u81f4\u547d\u7684\u3067\u3059\u3002<br \/>\nWhile\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u547d\u4ee4\u3092\u6295\u3052\u3066\u305d\u308c\u3092\u5225\u30d7\u30ed\u30bb\u30b9\u3067\u51e6\u7406\u3057\u3066\u6295\u3052\u3066\u3044\u308b\u3088\u3046\u3067\u3001<br \/>\n\u51e6\u7406\u304c\u7a7a\u632f\u308a\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n<p>\u66f4\u306bPrint\u547d\u4ee4\u3092\u9014\u4e2d\u306b\u631f\u3080\u3068\u4f55\u6545\u304b\u4e0a\u8a18\u306e\u7a7a\u632f\u308a\u304c\u6e1b\u3063\u3066\u51e6\u7406\u304c\u65e9\u304f\u5e30\u3063\u3066\u304f\u308b\u3068\u3044\u3046<br \/>\n\u8b0e\u306e\u73fe\u8c61\u3082\u78ba\u8a8d\u6e08\u307f\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u7d4c\u904e\u6642\u9593\u304c\u6b63\u78ba\u306b\u53d6\u308c\u305d\u3046\u3082\u306a\u3044\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u305f\u3081\u3001<br \/>\n\u30b7\u30fc\u30b1\u30f3\u30b5\u306e\u958b\u767a\u306bCircuitPython\u4f7f\u3046\u306e\u306f\u8ae6\u3081\u308b\u3068\u3044\u3046\u72b6\u614b\u3067\u3059\u3002<\/p>\n<h3>\u691c\u8a3c\u30b3\u30fc\u30c9<\/h3>\n<pre>RaspberryPiPico\u3067\u8a66\u3057\u3066\u307e\u3057\u305f\u3002<\/pre>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport time\r\nimport supervisor\r\nimport usb_midi\r\nimport adafruit_midi\r\nfrom adafruit_midi.note_off import NoteOff\r\nfrom adafruit_midi.note_on import NoteOn\r\n\r\n_TICKS_PERIOD = const(1&lt;&lt;29)\r\n_TICKS_MAX = const(_TICKS_PERIOD-1)\r\n_TICKS_HALFPERIOD = const(_TICKS_PERIOD\/\/2)\r\n\r\ndef ticks_add(ticks, delta):\r\n    &quot;Add a delta to a base number of ticks, performing wraparound at 2**29ms.&quot;\r\n    return (a + b) % _TICKS_PERIOD\r\n\r\ndef ticks_diff(ticks1, ticks2):\r\n    &quot;Compute the signed difference between two ticks values, assuming that they are within 2**28 ticks&quot;\r\n    diff = (ticks1 - ticks2) &amp; _TICKS_MAX\r\n    diff = ((diff + _TICKS_HALFPERIOD) &amp; _TICKS_MAX) - _TICKS_HALFPERIOD\r\n    return diff\r\n\r\ndef ticks_less(ticks1, ticks2):\r\n    &quot;Return true iff ticks1 is less than ticks2, assuming that they are within 2**28 ticks&quot;\r\n    return ticks_diff(ticks1, ticks2) &lt; 0\r\n\r\nUSB_MIDI_channel = 1 \r\nusb_midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=USB_MIDI_channel - 1)\r\n\r\nstart_time = time.monotonic() # \u96fb\u6e90\u6295\u5165\u6642\r\nusb_midi.send(NoteOn(55, 100))\r\nusb_midi.send(NoteOff(55, 100))\r\nusb_midi.send(NoteOn(55, 100))\r\nusb_midi.send(NoteOff(55, 100))\r\nusb_midi.send(NoteOn(55, 100))\r\nusb_midi.send(NoteOff(55, 100))\r\nusb_midi.send(NoteOn(55, 100))\r\nusb_midi.send(NoteOff(55, 100))\r\nelapsed_time = time.monotonic() - start_time\r\n# print(start_time)\r\n# print(&quot;do_something took %f seconds&quot;\r\n# % elapsed_time)\r\n\r\ntmp=0\r\ndst = time.monotonic()\r\n# time.monotonic()\r\n# print(dst)\r\nmst_ms=0\r\ntone=False\r\n\r\nwhile True:\r\n    tmp = time.monotonic()-dst\r\n    mst_ms+=tmp*1000\r\n    # time.sleep(0.001)\r\n    dst=time.monotonic()\r\n    # \u8b0e\u306e\u6319\u52d5\u3067\u901f\u5ea6\u304c\u4e0a\u304c\u308b\u306e\u3067\u8a18\u8f09\u3057\u3066\u308b\u3002\u306a\u3093\u3060\u308d\r\n    print()\r\n    print()\r\n    print()\r\n    print()\r\n\r\n    if mst_ms &gt;n 500:\r\n        mst_ms-n=500\r\n        if tone==False:\r\n            usb_midi.send(NoteOn(55, 100))\r\n            tone=True\r\n            print(&quot;on&quot;)\r\n        elif tone==True:\r\n            usb_midi.send(NoteOff(55, 100))\r\n            tone=False\r\n            print(&quot;off&quot;)\r\n<\/pre>\n<h3>\u4ee3\u308f\u308a\u306bArduino<\/h3>\n<p>\u6700\u8fd1\u306fArduino\u74b0\u5883\u3067RaspberryPiPico\u3092\u958b\u767a\u3059\u308b\u74b0\u5883\u3082\u6574\u3063\u3066\u304d\u3066\u308b\uff08\u7d50\u69cb\u524d\u306b\u8abf\u3079\u305f\u3051\u3069\u7d99\u7d9a\u3057\u3066\u958b\u767a\u3055\u308c\u3066\u308b\uff09\u306e\u3067\u3001\u3053\u308c\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u5bfe\u5fdc\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/earlephilhower\/arduino-pico\">earlephilhower\/arduino-pico: Raspberry Pi Pico Arduino core, for all RP2040 boards (github.com)<\/a><\/p>\n<p>C\u8a00\u8a9e\u4f7f\u3046\u306e\u306f\u3001\u81ea\u5206\u3068\u3057\u3066\u306f\u30e1\u30ac\u30c7\u30e2\u3068\u304b\u3067\u4f7f\u3063\u3066\u305f\u306e\u3067\u554f\u984c\u306a\u3044\u304b\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u8a66\u3057\u306bMIDI\u30ce\u30fc\u30c8\u3092\u51fa\u529b\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306bUSB-MIDI\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u300cAdafruit TinyUSB\u300d\u3067\u3059\u3002<br \/>\nPICO SDK\u3060\u3068\u8a2d\u8a08\u304c\u53e4\u304b\u3063\u305f\u308a\u3059\u308b\u3057\u3001\u672c\u5bb6\u306e\u307b\u3046\u3060\u3068\u547d\u4ee4\u306e\u540d\u524d\u304c\u307e\u3063\u305f\u304f\u9055\u3063\u3066\u308b\u306e\u3067\u6ce8\u610f\u3002<br \/>\n\uff08\u540c\u3058\u30e9\u30a4\u30d6\u30e9\u30ea\u4f7f\u3044\u3064\u3064\u5185\u90e8\u3067\u5f04\u308a\u307e\u304f\u3063\u3066\u308b\u306e\u3067\u3001\u540c\u540d\u306e\u8907\u6570\u7a2e\u985e\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u6319\u52d5\u304c\u9055\u3046\u307f\u305f\u3044\u3067\u3059\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;Arduino.h&gt;;\r\n#include &lt;Adafruit_TinyUSB.h&gt;;\r\n#include &lt;MIDI.h&gt;;\r\n\r\n\/\/ USB MIDI object\r\nAdafruit_USBD_MIDI usb_midi;\r\n\r\n\/\/ Create a new instance of the Arduino MIDI Library,\r\n\/\/ and attach usb_midi as the transport.\r\nMIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);\r\n\r\n\/\/ Variable that holds the current position in the sequence.\r\nuint32_t position = 0;\r\n\r\nvoid setup()\r\n{\r\n#if defined(ARDUINO_ARCH_MBED) &amp;&amp; defined(ARDUINO_ARCH_RP2040)\r\n    \/\/ Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040\r\n    TinyUSB_Device_Init(0);\r\n#endif\r\n\r\n    pinMode(LED_BUILTIN, OUTPUT);\r\n    \/\/usb_midi.setStringDescriptor(&quot;TinyUSB MIDI&quot;);\r\n\r\n    \/\/ Initialize MIDI, and listen to all MIDI channels\r\n    \/\/ This will also call usb_midi's begin()\r\n    MIDI.begin(MIDI_CHANNEL_OMNI);\r\n\r\n    Serial.begin(115200);\r\n\r\n    \/\/ wait until device mounted\r\n    while( !TinyUSBDevice.mounted() )\r\n    delay(1);\r\n}\r\n\r\nvoid loop()\r\n{\r\n    static uint32_t start_ms = 0;\r\n    if ( millis() - start_ms &gt; 266 )\r\n    {\r\n\r\n        int cnt=0;\r\n        bool tone_on=false;\r\n        const int tone_time=10000000;\r\n        int note_no=0;\r\n\r\n        \/\/1000000\u56de\u3067\u3082\u554f\u984c\u306a\u3044\u901f\u5ea6\r\n        while(1){\r\n            if( cnt &gt; tone_time){\r\n                if( tone_on == false){\r\n\r\n                    note_no=random(20, 70);\r\n                    MIDI.sendNoteOn(note_no, 127, 1);\r\n                    tone_on=true;\r\n                }else{\r\n                    MIDI.sendNoteOff(note_no, 0, 1); \r\n                    tone_on=false;\r\n                }\r\n                cnt-=tone_time;\r\n            }\r\n            cnt++;\r\n        }\r\n    }  \r\n}\r\n<\/pre>\n<h3>\u53c2\u8003\u8cc7\u6599<\/h3>\n<p><a href=\"https:\/\/github.com\/adafruit\/Adafruit_TinyUSB_Arduino\/tree\/master\/examples\/MIDI\/midi_test\">Adafruit_TinyUSB_Arduino\/examples\/MIDI\/midi_test at master \u00b7 adafruit\/Adafruit_TinyUSB_Arduino (github.com)<\/a><\/p>\n<p><a href=\"https:\/\/blog.boochow.com\/article\/rpi-pico-midi-monitor.html\">Raspberry Pi Pico\u3067MIDI\u30e2\u30cb\u30bf\u3092\u4f5c\u3063\u3066\u307f\u305f \u2013 \u697d\u3057\u304f\u3084\u308d\u3046\u3002 (boochow.com)<\/a><\/p>\n<p><a href=\"http:\/\/radiopench.blog96.fc2.com\/blog-entry-1179.html\">\u30e9\u30b8\u30aa\u30da\u30f3\u30c1 Raspberry Pi Pico\u306772LED\u306e\u30af\u30ea\u30b9\u30de\u30b9\u30c4\u30ea\u30fc\u30a4\u30eb\u30df\u30cd\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308b (fc2.com)<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u30b7\u30fc\u30b1\u30f3\u30b5\u958b\u767a \u4e00\u5ea6\u30ad\u30fc\u30dc\u30fc\u30c9\u3092\u81ea\u4f5c\u59cb\u3081\u305f\u3068\u304d\u306b\u8a66\u3057\u306b\u65e2\u5b58\u306e\u30ad\u30fc\u30dc\u30fc\u30c9\u306e\u30d5\u30a1\u30fc\u30e0\u3092\u6539\u9020\u3057\u3066\u3001 \u30b7\u30fc\u30b1\u30f3\u30b5\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002 \u3067\u3001\u305d\u308d\u305d\u308d\u57fa\u677f\u304b\u3089\u81ea\u4f5c\u3067\u3082\u554f\u984c\u306a\u304b\u308d\u3046\u3068\u8003\u3048\u3066\u3001\u6628\u65e5\u306f\u57fa\u677f\u306e\u8a2d\u8a08\u3092\u884c\u3044\u3001 \u30d7\u30ed\u30b0\u30e9\u30e0\u306e&hellip; <span class=\"clear\"><\/span><a href=\"https:\/\/machiaworx.net\/?p=1584\" class=\"more-link read-more\" rel=\"bookmark\"><span class=\"screen-reader-text\">\u30cf\u30fc\u30c9\u30b7\u30fc\u30b1\u30f3\u30b5\u958b\u767a\u3002\uff08\u305d\u306e\uff11\u30fb\u30d7\u30ed\u30b0\u30e9\u30e0\u691c\u8a3c\uff09<\/span><i class=\"fa fa-arrow-right\"><\/i> \u306e\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,23,4],"tags":[],"class_list":["post-1584","post","type-post","status-publish","format-standard","hentry","category-synth-dev","category-embed","category-pgm"],"_links":{"self":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts\/1584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1584"}],"version-history":[{"count":11,"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts\/1584\/revisions"}],"predecessor-version":[{"id":1651,"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts\/1584\/revisions\/1651"}],"wp:attachment":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}