{"id":584,"date":"2019-04-02T07:09:13","date_gmt":"2019-04-02T07:09:13","guid":{"rendered":"http:\/\/iludis.de\/?p=584"},"modified":"2019-05-09T13:47:00","modified_gmt":"2019-05-09T13:47:00","slug":"musterloesung-moore-automat-am-cpx","status":"publish","type":"post","link":"https:\/\/iludis.de\/?p=584","title":{"rendered":"Musterl\u00f6sung Moore-Automat am CPX"},"content":{"rendered":"<p>Ampelschaltung als Moore-Automat<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-605 size-full\" src=\"https:\/\/iludis.de\/wp-content\/uploads\/2019\/04\/Ampel.png\" alt=\"\" width=\"604\" height=\"469\" srcset=\"https:\/\/iludis.de\/wp-content\/uploads\/2019\/04\/Ampel.png 604w, https:\/\/iludis.de\/wp-content\/uploads\/2019\/04\/Ampel-300x233.png 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import board\r\nimport time\r\nimport neopixel\r\nimport touchio\r\n\r\nNeopixelReihe = neopixel.NeoPixel(board.NEOPIXEL, 10)\r\nNeopixelReihe.auto_write = False\r\nB_A1 = touchio.TouchIn(board.A1)\r\nzustand = &quot;q0&quot;\r\nstartzeit = time.monotonic()\r\ndt = time.monotonic()\r\n\r\nAusgabeR = [(16, 0, 0), (0, 0, 0), (0, 0, 0)]\r\nAusgabeY = [(0, 0, 0), (16, 16, 0), (0, 0, 0)]\r\nAusgabeG = [(0, 0, 0), (0, 0, 0), (0, 16, 0)]\r\nAusgabeRY = [(16, 0, 0), (16, 16, 0), (0, 0, 0)]\r\n\r\n\r\ndef resetTimer():\r\n    global startzeit\r\n    startzeit = time.monotonic()\r\n\r\n\r\ndef macheAusgabe(zustand):\r\n    if zustand == &quot;q0&quot;:\r\n        NeopixelReihe[2] = AusgabeG[0]\r\n        NeopixelReihe[1] = AusgabeG[1]\r\n        NeopixelReihe[0] = AusgabeG[2]\r\n    \r\n    if zustand == &quot;q1&quot;:\r\n        NeopixelReihe[2] = AusgabeY[0]\r\n        NeopixelReihe[1] = AusgabeY[1]\r\n        NeopixelReihe[0] = AusgabeY[2]\r\n        \r\n    if zustand == &quot;q2&quot;:\r\n        NeopixelReihe[2] = AusgabeR[0]\r\n        NeopixelReihe[1] = AusgabeR[1]\r\n        NeopixelReihe[0] = AusgabeR[2]\r\n\r\n    if zustand == &quot;q3&quot;:\r\n        NeopixelReihe[2] = AusgabeRY[0]\r\n        NeopixelReihe[1] = AusgabeRY[1]\r\n        NeopixelReihe[0] = AusgabeRY[2]\r\n        NeopixelReihe.show()\r\n\r\n\r\ndef zustandsuebergangsfunktion():\r\n    global zustand\r\n    global dt\r\n    global startzeit\r\n    if zustand == &quot;q0&quot;:\r\n        macheAusgabe(zustand)\r\n        if B_A1.value:\r\n            zustand = &quot;q1&quot;\r\n            resetTimer()\r\n            return\r\n        \r\n    elif zustand == &quot;q1&quot;:\r\n        macheAusgabe(zustand)\r\n        if dt &gt; 1.0:\r\n            resetTimer()\r\n            zustand = &quot;q2&quot;\r\n            return\r\n    \r\n    elif zustand == &quot;q2&quot;:\r\n        macheAusgabe(zustand)\r\n        if dt &gt; 1.0:\r\n            resetTimer()\r\n            zustand = &quot;q3&quot;\r\n            return\r\n    \r\n    elif zustand == &quot;q3&quot;:\r\n        macheAusgabe(zustand)\r\n        if dt &gt; 1.0:\r\n            resetTimer()\r\n            zustand = &quot;q0&quot;\r\n            return\r\n\r\nwhile True:\r\n    zustandsuebergangsfunktion()\r\n    dt = time.monotonic() - startzeit\r\n    time.sleep(0.1)\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ampelschaltung als Moore-Automat import board import time import neopixel import touchio NeopixelReihe = neopixel.NeoPixel(board.NEOPIXEL, 10) NeopixelReihe.auto_write = False B_A1 = touchio.TouchIn(board.A1) zustand = &quot;q0&quot; startzeit = time.monotonic() dt = time.monotonic() AusgabeR = [(16, 0, 0), (0, 0, 0), (0, 0, 0)] AusgabeY = [(0, 0, 0), (16, 16, 0), (0, 0, 0)] AusgabeG = [(0,&hellip; <\/p>\n<p class=\"toivo-read-more\"><a href=\"https:\/\/iludis.de\/?p=584\" class=\"more-link\">Read more <span class=\"screen-reader-text\">Musterl\u00f6sung Moore-Automat am CPX<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-584","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-uncategorized","7":"entry"},"_links":{"self":[{"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/posts\/584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/iludis.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=584"}],"version-history":[{"count":0,"href":"https:\/\/iludis.de\/index.php?rest_route=\/wp\/v2\/posts\/584\/revisions"}],"wp:attachment":[{"href":"https:\/\/iludis.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iludis.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iludis.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}