{"id":2734,"date":"2018-02-07T17:27:50","date_gmt":"2018-02-07T08:27:50","guid":{"rendered":"http:\/\/nantoka.filmm.info\/blog\/?p=2734"},"modified":"2018-02-09T10:38:30","modified_gmt":"2018-02-09T01:38:30","slug":"microbit%e3%80%80%e3%81%8a%e5%87%ba%e3%81%8b%e3%81%91%e3%82%b5%e3%83%9d%e3%83%bc%e3%83%88","status":"publish","type":"post","link":"https:\/\/nantoka.filmm.info\/blog\/?p=2734","title":{"rendered":"micro:bit\u3000\u304a\u51fa\u304b\u3051\u30b5\u30dd\u30fc\u30c8"},"content":{"rendered":"<p>\u304a\u51fa\u304b\u3051\u30b5\u30dd\u30fc\u30c8\u30b7\u30b9\u30c6\u30e0(ver2\u304f\u3089\u3044\u3000\u3042\u307e\u308a\u52d5\u4f5c\u3057\u306a\u3044\uff09<\/p>\n<pre class=\"lang:python decode:true\"># Add your Python code here. E.g.\r\nfrom microbit import *\r\n#import microbit\r\nimport music\r\nimport radio\r\nimport os\r\n\r\ndisplay.scroll('RadioV1')\r\nradio.config(channel=10, power=4)#BLE init\r\nradio.on()#BLE ON\r\n\r\nbtnChk = False\r\nmyID = 1\r\ngrCount  = 1\r\ngrChk = False\r\noneTime = False\r\ntimerA = 0\r\ntimerB = 0\r\n#tune = [\"C4:4\", \"D4:4\", \"E4:4\", \"C4:4\", \"C4:4\", \"D4:4\", \"E4:4\", \"C4:4\",\"E4:4\", \"F4:4\", \"G4:8\", \"E4:4\", \"F4:4\", \"G4:8\"]\r\ntune2 = [\"E4:1\"]\r\n\r\n#File read\r\nif 'id.txt' in os.listdir():\r\n    with open('id.txt') as my_id:\r\n        myidtxt = my_id.read()\r\n        myID = int(myidtxt) \r\nif 'gr.txt' in os.listdir():\r\n    with open('gr.txt') as gr_id:\r\n        mygridtxt = gr_id.read()\r\n        grCount  = int(mygridtxt)\r\n\r\nwhile True:\r\n    if button_a.is_pressed() and button_b.is_pressed():\r\n        ##setingMode\r\n        if btnChk is False:\r\n            btnChk = True\r\n            display.scroll('SET')\r\n            display.scroll('ID=' + str(myID))\r\n        elif btnChk is True:\r\n            btnChk = False #end set mode\r\n            shakeChk = False #end shake mode\r\n            display.show(Image.YES)\r\n    elif button_a.is_pressed():\r\n        if btnChk is True and grChk is False:#ID count mode\r\n            if myID &lt; 20:\r\n                myID += 1\r\n            else:\r\n                myID = 0\r\n            display.scroll('ID' + str(myID))\r\n            #sleep(200)\r\n            #display.clear()\r\n        elif btnChk is False and grChk is True:#group count mode\r\n            if grCount &lt; 20:\r\n                grCount += 1\r\n            else:\r\n                grCount = 0\r\n            display.scroll('GR' + str(grCount))\r\n        else:\r\n            music.play(tune2)\r\n    elif button_b.is_pressed():\r\n        if btnChk is False and grChk is False:\r\n            radio.config(power=7)#HelpMode\r\n            radio.send('HELP')\r\n            radio.config(power=4)#HelpMode\r\n            display.scroll('HELP')\r\n            sleep(800)\r\n            display.clear()\r\n        elif btnChk is False and grChk is True:#end gr set mode\r\n            btnChk = False #end set mode\r\n            grChk = False #end shake mode\r\n            radio.send(str(grCount))\r\n            display.show(Image.YES)\r\n            sleep(500)\r\n            display.clear()\r\n            #File Save\r\n            with open('id.txt', 'w') as my_id:\r\n                my_id.write(str(myID))\r\n            with open('gr.txt', 'w') as gr_id:\r\n                gr_id.write(str(grCount))\r\n        if btnChk is True and grChk is False:#end id set mode\r\n            btnChk = False\r\n            grChk = True#to Group set mode\r\n            display.show(Image.YES)\r\n            sleep(500)\r\n            display.clear()\r\n            display.scroll('GR=' + str(grCount))\r\n    #else:\r\n        #display.scroll('')\r\n        \r\n    s = radio.receive()\r\n    if s == 'flash':\r\n        display.scroll('Recieve')\r\n    elif s == 'HELP':\r\n        display.scroll('!')\r\n        music.play(music.RINGTONE)\r\n        display.show(Image.SAD)\r\n        sleep(3000)\r\n        display.clear()\r\n    elif(s):\r\n        if btnChk is False and grChk is False:\r\n            grCount = int(s)\r\n            display.scroll('GR=' + str(grCount))\r\n            with open('gr.txt', 'w') as gr_id:\r\n                gr_id.write(str(grCount))\r\n   # display.show(Image.HEART)\r\n   \r\n   if running_time() &gt; timerA:\r\n       #sendID\r\n    sleep(100)\r\n    \r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u304a\u51fa\u304b\u3051\u30b5\u30dd\u30fc\u30c8\u30b7\u30b9\u30c6\u30e0(ver2\u304f\u3089\u3044\u3000\u3042\u307e\u308a\u52d5\u4f5c\u3057\u306a\u3044\uff09 # Add your Python code here. E.g. from microbit import * #import microbit impor &hellip; <a href=\"https:\/\/nantoka.filmm.info\/blog\/?p=2734\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">micro:bit\u3000\u304a\u51fa\u304b\u3051\u30b5\u30dd\u30fc\u30c8<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,51],"tags":[],"class_list":["post-2734","post","type-post","status-publish","format-standard","hentry","category-microbit","category-python"],"_links":{"self":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2734"}],"version-history":[{"count":3,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2734\/revisions"}],"predecessor-version":[{"id":2740,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2734\/revisions\/2740"}],"wp:attachment":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}