{"id":217891,"date":"2014-04-02T19:12:02","date_gmt":"2014-04-02T15:12:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=217891"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=217891","title":{"rendered":"<span class=\"post_title\">\u0421\u043e\u0435\u0434\u0435\u043d\u044f\u0435\u043c \u044d\u043b\u043b\u0438\u043f\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440 \u0438 pygame<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f! \u0421\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u0440\u0430\u0432\u043c\u044b \u044f \u043f\u0440\u0438\u043a\u0443\u043f\u0438\u043b \u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043f\u0440\u0438\u0431\u043e\u0440. <br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/348\/95d\/61e\/34895d61e200408c80dcdde67d010924.jpg\"\/><br \/>  \u0421\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u043f\u0440\u044f\u043c\u044b\u043c\u0438 \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u043d \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0434\u043d\u043e \u00ab\u043d\u043e\u00bb, \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u043e\u0441\u044c \u043e\u043d\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u043f\u0443\u0442\u0430\u043b\u0441\u044f \u0432 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u0445, \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0438\u0434\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u0442\u043e \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u043b\u0447\u0430\u043b. \u0418 \u0440\u0435\u0448\u0435\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u0441\u2026 \u043d\u0443 \u0432\u044b \u043f\u043e\u043d\u044f\u043b\u0438.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041a\u0430\u043a \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440 \u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440<\/h4>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435, \u0441 \u0447\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u2014 \u043d\u0430\u0439\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440. \u041f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u043c \u0437\u0432\u0435\u043d\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u0443 <b>Arduino<\/b>. <br \/>  \u041f\u043e\u0447\u0435\u043c\u0443 <b>Arduino<\/b>? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u043d\u0435\u0442 \u043d\u0438 \u0447\u0435\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e.<br \/>  \u041f\u0440\u0438 \u043e\u0441\u043c\u043e\u0442\u0440\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043e\u0442 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440\u0430 \u043a \u0434\u0430\u0442\u0447\u0438\u043a\u0443 \u0438\u0434\u0443\u0442 \u0434\u0432\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0430.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/b24\/dbb\/d14\/b24dbbd14abd32b9627c945e41d212ed.png\" alt=\"image\"\/><br \/>  \u0427\u0435\u0433\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u043a \u043f\u0438\u043d\u0430\u043c <b>Arduino<\/b>. \u0427\u0442\u043e \u0438 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043f\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u0441\u0445\u0435\u043c\u0435<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/692\/fbf\/ced\/692fbfced4e14653591a2d7206594c8f.png\"\/><br \/>  \u041d\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442 <b>A0<\/b> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0434\u0430\u043b\u0435\u0439, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b \u0440\u0430\u0437\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b. <br \/>  \u0412 \u0445\u043e\u0434\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043d\u044b \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u043e\u0434\u0430\u0447\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043e\u0442 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0434\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u0438 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u043d\u0430 \u0442\u0430\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435: <br \/>  \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u0431\u0435\u0437\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e \u043f\u043e\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b <b>\u00ab0\u00bb<\/b>, \u0437\u0430\u0442\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0441\u0434\u0435\u043b\u0430\u043d \u0448\u0430\u0433 \u043d\u0430 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440\u0435, \u043f\u043e\u0434\u0430\u0435\u0442\u0441\u044f<b> \u00ab1\u00bb<\/b>. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u0441\u043d\u043e\u0432\u0430 <b>\u00ab0\u00bb<\/b> \u0438 \u0442\u0430\u043a \u043f\u043e \u043a\u0440\u0443\u0433\u0443.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u0432\u043e\u0436\u0443 sketch<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">int pin = A0; int ledPin = 13; int minSignal = 600; bool stateUp = false; bool lastState = false; bool oneStep = false; void setup() { \tpinMode(pin, INPUT); \tpinMode(ledPin, OUTPUT); \tSerial.begin(9600); } void loop() { \tint signal = analogRead(pin); \tif (signal &gt; minSignal){ \t\tstateUp = true; \t} \telse{ \t\tstateUp = false; \t} \tif (lastState != stateUp && lastState == false){ \t       oneStep = not oneStep; \t} \telse { \t} \tlastState = stateUp; \tSerial.println(oneStep); \tdigitalWrite(ledPin, oneStep); \/\/\u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0418\u0433\u0440\u0430<\/h4>\n<p>  <i>\u0427\u0442\u043e \u0435\u0449\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 <b>pygame<\/b> \u0435\u0441\u043b\u0438 \u043d\u0435 \u0438\u0433\u0440\u0443?<\/i><\/p>\n<h5>\u0418\u0434\u0435\u044f<\/h5>\n<p>  \u042d\u043b\u043b\u0438\u043f\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440 \u044d\u0442\u043e \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u044f \u0445\u043e\u0434\u044c\u0431\u044b \u043d\u0430 \u043b\u044b\u0436\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u043d\u043a\u0430 \u043b\u044b\u0436\u043d\u0438\u043a\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0442\u0440\u0435\u043d\u0430\u0436\u0435\u0440\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436 \u0432 \u0438\u0433\u0440\u0435. \u0421\u043f\u0435\u0440\u0432\u0430 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\\\u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430, \u043d\u043e \u0432 \u0438\u0442\u043e\u0433\u0435, \u0440\u0435\u0448\u0438\u043b \u043e\u0442\u0434\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438. <\/p>\n<h5>\u0420\u0430\u0441\u0447\u0435\u0442\u044b<\/h5>\n<p>  \u041e\u043f\u044b\u0442\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u043c \u0431\u044b\u043b\u043e \u0432\u044b\u044f\u0441\u043d\u0435\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u00ab\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445\u00bb \u043e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430\u0445 \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u043d\u044b\u0439 \u043e\u0431\u043e\u0440\u043e\u0442 \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f 4-\u043c \u043c\u0435\u0442\u0440\u0430\u043c. \u042d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u043d\u0435 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0438\u0441\u043a. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0430 \u0430\u043a\u0441\u0438\u043e\u043c\u0443. <br \/>  \u041d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u0440\u0430\u0441\u0441\u0435 1 \u043c\u0435\u0442\u0440 \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f 1 \u043f\u0438\u043a\u0441\u0435\u043b\u044e. \u0422.\u0435. \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043f\u0435\u0440\u0441\u043d\u0430\u0436\u0430 \u043d\u0430 4 \u043f\u0438\u043a\u0441\u0435\u043b\u044f \u0432\u043f\u0435\u0440\u0435\u0434.<br \/>  \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433.<br \/>  <b>v<\/b> = <b>s<\/b> \/<b> t<\/b><br \/>  <b>s<\/b> = 4 \u043c.<br \/>  <b>t<\/b> \u2014 \u0432\u0440\u0435\u043c\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430. <br \/>  <i>*\u043e\u0434\u0438\u043d \u0448\u0430\u0433 \u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u043e\u0431\u043e\u0440\u043e\u0442 \u043f\u0435\u0434\u0430\u043b\u0435\u0439.<\/i><\/p>\n<h5>\u0410\u0437\u0430\u0440\u0442<\/h5>\n<p>  \u0414\u0430, \u0431\u0443\u0434\u0443\u0442 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0438 \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u0443\u0445\u0430 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f. <br \/>  \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0443\u0434\u0435\u0448\u044c \u043d\u0435 \u0441 \u043a\u0435\u043c-\u0442\u043e \u0430 \u0441 \u0441\u0430\u043c\u0438\u043c \u0441\u043e\u0431\u043e\u0439, <b>\u0432\u0447\u0435\u0440\u0430\u0448\u043d\u0438\u043c<\/b>? \u0421\u043a\u0430\u0437\u0430\u043d\u043e \u2014 \u0441\u0434\u0435\u043b\u0430\u043d\u043e. <br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/203\/a25\/386\/203a25386b15eb259c2ad15e573e8bd5.png\"\/><br \/>  \u0421\u0432\u0435\u0440\u0445\u0443 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0432\u0447\u0435\u0440\u0430\u0448\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u043c \u2014 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0437\u0430\u0431\u0435\u0433\u0430 <s>\u043d\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u0435\u0441\u044c, \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0432\u0443\u0447\u0438\u0442 \u043a\u0440\u0443\u0447\u0435.<\/s><\/p>\n<h4>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438<\/h4>\n<h5>\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h5>\n<p>  \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0440\u0430\u0437 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0431\u0435\u0433\u0430\u0445, \u043d\u0443\u0436\u043d\u0430 \u0411\u0414. \u042f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <b>mysql<\/b>. \u0412 <b>python<\/b> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <b>MySQLdb<\/b>. \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0437\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441<b> DataManger<\/b>. <br \/>  \u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/600\/db0\/afd\/600db0afdc1e29f57e363e296f7f1335.png\"\/>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">\u0441lass DataManager:     def __init__(self):         self.time = time         self.currentTimeForLastRace = datetime.now()         self.currentTime = self.time.time()         self.speed = 0         self.db = MySQLdb.connect(host=&quot;localhost&quot;, user=&quot;root&quot;, passwd=&quot;root&quot;, db=&quot;skirunner&quot;, charset='utf8')         self.cursor = self.db.cursor()         self.isGetLastRaceSpeeds = False         self.dataLastRace = []         self.lastRaceMinDate = datetime.now()         self.value = 0         self.lastValue = 0         self.impulse = 0         self.isRaceStart = False         self.currentRaceId = -1         self.currentDistanceId = -1         self.currentProfileId = -1      def getImpulse(self, value):         self.impulse = 0          if self.time.time() - self.currentTime &gt; RESET_SPEED_TIME:             self.speed = 0         self.value = value         if self.value != self.lastValue:             time = self.time.time() - self.currentTime             self.impulse = POWER_IMPULSE             self.isRaceStart = True              self.speed = STEP \/ time # \u043c\u0435\u0442\u0440\u044b \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443             self.currentTime = self.time.time()             self.lastValue = self.value          return  self.impulse      def getLastRaceDistanceAtCurrentTime(self, raceId,currentTime):         lastRaceDistance = 0         dateFormat = &quot;%Y-%m-%d %H:%M:%S.%f&quot;         if  not self.isGetLastRaceSpeeds:              sql = &quot;&quot;&quot;SELECT min(date) FROM runLog WHERE race_id = %s&quot;&quot;&quot; % raceId             self.cursor.execute(sql)             data = self.cursor.fetchall()             for rec in data:                 self.lastRaceMinDate = datetime.strptime(rec[0],dateFormat)             sql = &quot;&quot;&quot;SELECT distance,date FROM runLog WHERE race_id = %s ORDER BY date DESC&quot;&quot;&quot; % raceId             self.cursor.execute(sql)             self.dataLastRace = self.cursor.fetchall()             self.isGetLastRaceSpeeds = True          if self.isRaceStart:             time = datetime.now() - datetime.fromtimestamp(currentTime)             for rec in self.dataLastRace:                 distance, date = rec                 if time &lt;= (datetime.strptime(date,dateFormat) - self.lastRaceMinDate):                     lastRaceDistance = distance         return  lastRaceDistance <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>\u0413\u0440\u0430\u0444\u0438\u043a\u0430<\/h5>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0437 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0430 \u0432\u044b\u0448\u0435, \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0430\u044f, \u043d\u043e \u043d\u0435 <s>\u043d\u044f\u0448\u043d\u043e\u0441\u0442\u044c<\/s> \u044d\u0442\u043e \u0442\u0443\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0435. \u0414\u043b\u044f \u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <b>pygame<\/b>. \u041e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f <a href=\"http:\/\/habrahabr.ru\/post\/193888\/\">\u0443\u0436\u0435<\/a> \u043f\u0438\u0441\u0430\u043b.<\/p>\n<h5>\u0424\u043e\u0440\u043c\u044b<\/h5>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/1ff\/d2a\/92a\/1ffd2a92a1764574afcef14291e80701.png\"\/><br \/>  \u0414\u043b\u044f \u0444\u043e\u0440\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <b>PyQt<\/b>.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">class FormProfile(QMainWindow):      def __init__(self):         super(QMainWindow, self).__init__()         uic.loadUi('%s\/ui\/frm_profile.ui' % DIR, self)         self.cb_profile_load()         self.te_newProfile.hide()         self.bt_addProfile.hide()         self.bt_cancel.hide()         self.lb_add.hide()         self.move(QDesktopWidget().availableGeometry().center() - self.frameGeometry().center())          self.connect(self.bt_ok, SIGNAL(&quot;clicked()&quot;), self.bt_ok_clicked)         self.connect(self.bt_new, SIGNAL(&quot;clicked()&quot;), self.bt_new_clicked)         self.connect(self.bt_addProfile,SIGNAL(&quot;clicked()&quot;), self.bt_addProfile_clicked)         self.connect(self.bt_cancel, SIGNAL(&quot;clicked()&quot;), self.bt_cancel_clicked)         self.connect(self.bt_graph, SIGNAL(&quot;clicked()&quot;), self.bt_graph_clicked)      def bt_ok_clicked(self):         self.profileId = self.cb_profile.itemData(self.cb_profile.currentIndex()).toString()         self.formDistance = FormDistance(self.profileId)         self.formDistance.show()         self.hide() <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u043a\u043e\u043d. \u041d\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 <b>MS studio<\/b>. <br \/>  \u0424\u043e\u0440\u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 <b>Qt 4 Creator<\/b>.<br \/>  \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u0445 \u0432 \u043a\u043e\u0434 <\/p>\n<pre><code class=\"python\">uic.loadUi('%s\/ui\/frm_profile.ui' % DIR, self) <\/code><\/pre>\n<p>  \u0421\u0432\u044f\u0437\u0430\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b <\/p>\n<pre><code class=\"python\">        self.connect(self.bt_ok, SIGNAL(&quot;clicked()&quot;), self.bt_ok_clicked)         self.connect(self.bt_new, SIGNAL(&quot;clicked()&quot;), self.bt_new_clicked)         self.connect(self.bt_addProfile,SIGNAL(&quot;clicked()&quot;), self.bt_addProfile_clicked)         self.connect(self.bt_cancel, SIGNAL(&quot;clicked()&quot;), self.bt_cancel_clicked)         self.connect(self.bt_graph, SIGNAL(&quot;clicked()&quot;), self.bt_graph_clicked) <\/code><\/pre>\n<p>  \u0418 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043b  <\/p>\n<pre><code class=\"python\">        self.formProfile = FormProfile()         self.formProfile.show() <\/code><\/pre>\n<h5>\u0413\u0440\u0430\u0444\u0438\u043a\u0438<\/h5>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/b6a\/26e\/0a7\/b6a26e0a7fef6a58107b1bfe765db17b.png\"\/><br \/>  \u0414\u043b\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 matplotlib.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0443\u0442 \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import matplotlib.pyplot as plt     def bt_averageSpeed_clicked(self):         ...         plt.plot_date(dates, values,'b')         plt.plot_date(dates, values,'bo')         averageSpeed = len(values) &gt; 0 and (lambda: sum(values) \/ len(values)) or (lambda: 0)         plt.xlabel(u&quot;\u0421\u0440\u0435\u0434\u043d\u044f\u044f-\u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c= %.2f \u043c\/\u0441 \u0438\u043b\u0438 %.2f \u043a\u043c\/\u0447&quot; % (float(averageSpeed()),float(averageSpeed()) \/ 1000 * 3600))         plt.ylabel(u&quot;\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c (\u043c\/\u0441)&quot;)         plt.title(u&quot;\u0413\u0440\u0430\u0444\u0438\u043a \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u043e\u0444\u0438\u043b\u044f %s&quot; % dm.getProfileNameById(self.profileId))         plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d\/%m\/%y'))         plt.gcf().autofmt_xdate()         plt.grid(True)         plt.show() <\/code><\/pre>\n<p>  \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u044b, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0435 \u0448\u0440\u0438\u0444\u0442\u044b.  <\/p>\n<pre><code class=\"python\">from matplotlib import rc    font = {'family': 'Droid Sans',         'weight': 'normal',         'size': 14}         rc('font', **font) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 arduino<\/h5>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <b>serial<\/b>.<br \/>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435.   <\/p>\n<pre><code class=\"python\">def getDataFromSimulator():     global valueFromSimulator, isRunnig     ser = serial.Serial('\/dev\/ttyACM0', 9600)     while isRunnig:        value =  ser.readline()        try:            valueFromSimulator = int(value)        except:            pass <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <b>valueFromSimulator<\/b> \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a \u0434\u0432\u0443\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.  <\/p>\n<pre><code class=\"python\">t1 = threading.Thread(target=main,args = (self.profileId,self.distanceId)) t2 = threading.Thread(target=getDataFromSimulator) t2.start() t1.start() <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u0438\u0434\u0435\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043b\u043e\u0445\u043e\u0433\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430<\/h4>\n<p>  \u041a\u0430\u043a \u0438 \u0437\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438.<br \/>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/5iXaYWgGmR0?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>  <i>\u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c, \u043a\u0440\u0438\u0442\u0438\u043a\u0435 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c.<\/i>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/217891\/\"> http:\/\/habrahabr.ru\/post\/217891\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f! \u0421\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u0440\u0430\u0432\u043c\u044b \u044f \u043f\u0440\u0438\u043a\u0443\u043f\u0438\u043b \u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043f\u0440\u0438\u0431\u043e\u0440. <br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/348\/95d\/61e\/34895d61e200408c80dcdde67d010924.jpg\"\/><br \/>  \u0421\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u043f\u0440\u044f\u043c\u044b\u043c\u0438 \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u043d \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0434\u043d\u043e \u00ab\u043d\u043e\u00bb, \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u043e\u0441\u044c \u043e\u043d\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u043f\u0443\u0442\u0430\u043b\u0441\u044f \u0432 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u0445, \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0438\u0434\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u0442\u043e \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u043b\u0447\u0430\u043b. \u0418 \u0440\u0435\u0448\u0435\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043f\u0438\u0434\u043e\u043c\u0435\u0442\u0440 \u0441\u2026 \u043d\u0443 \u0432\u044b \u043f\u043e\u043d\u044f\u043b\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217891","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217891"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217891\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}