{"id":421,"date":"2014-10-05T12:45:32","date_gmt":"2014-10-05T10:45:32","guid":{"rendered":"http:\/\/www.xpablo.cz\/?p=421"},"modified":"2014-10-05T12:47:44","modified_gmt":"2014-10-05T10:47:44","slug":"arduino-casovani-pomoci-intervalu","status":"publish","type":"post","link":"http:\/\/www.xpablo.cz\/?p=421","title":{"rendered":"Arduino &#8211; \u010casov\u00e1n\u00ed pomoc\u00ed interval\u016f"},"content":{"rendered":"<p><a href=\"https:\/\/www.xpablo.cz\/wp-content\/uploads\/2014\/10\/IMG_8754_web.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-422 alignleft\" src=\"https:\/\/www.xpablo.cz\/wp-content\/uploads\/2014\/10\/IMG_8754_web-300x225.jpg\" alt=\"IMG_8754_web\" width=\"300\" height=\"225\" srcset=\"http:\/\/www.xpablo.cz\/wp-content\/uploads\/2014\/10\/IMG_8754_web-300x225.jpg 300w, http:\/\/www.xpablo.cz\/wp-content\/uploads\/2014\/10\/IMG_8754_web-1024x768.jpg 1024w, http:\/\/www.xpablo.cz\/wp-content\/uploads\/2014\/10\/IMG_8754_web.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>Pokud to pova\u017euji za vhodn\u00e9, tak v n\u011bkter\u00fdch projektech pou\u017e\u00edv\u00e1m platformu Arduino. Koncepce programov\u00e9 konstrukce aplikace pro Arduino spo\u010d\u00edv\u00e1 ve dvou hlavn\u00edch metod\u00e1ch &#8211; <strong>setup()<\/strong> a <strong>loop()<\/strong>, ve kter\u00e9 program neust\u00e1le b\u011b\u017e\u00ed. Pro pohodln\u011bj\u0161\u00ed pr\u00e1ci s obsluhou periodick\u00fdch proces\u016f jsem napsal jednoduchou knihovnu, kter\u00e1 tyto \u00fakoly umo\u017e\u0148uje napsat velmi elegantn\u00edm zp\u016fsobem.<!--more-->Knihovna\u00a0<a href=\"https:\/\/www.xpablo.cz\/wp-content\/uploads\/2014\/10\/interval.zip\">interval<\/a> vytv\u00e1\u0159\u00ed \u010dasovac\u00ed objekty a zp\u0159\u00edstup\u0148uje dv\u011b metody &#8211; metodu <strong>set<\/strong> a metodu <strong>expired<\/strong>. Metoda <strong>set<\/strong> se pou\u017e\u00edv\u00e1 k nastaven\u00ed timeoutu a definici za\u010d\u00e1tku \u010dasov\u00e1n\u00ed, metoda <strong>expired<\/strong> pak slou\u017e\u00ed k ov\u011b\u0159en\u00ed, zda nastaven\u00fd interval ji\u017e vypr\u0161el. Zaj\u00edmavost\u00ed je, \u017ee knihovna korektn\u011b o\u0161et\u0159uje p\u0159ete\u010den\u00ed vnit\u0159n\u00edho milisekundov\u00e9ho \u010d\u00edta\u010de, tak\u017ee nehroz\u00ed nebezpe\u010d\u00ed \u0161patn\u00e9ho \u010dasov\u00e1n\u00ed i p\u0159i velmi dlouh\u00e9 dob\u011b chodu za\u0159\u00edzen\u00ed.<\/p>\n<p>P\u0159\u00edklad pou\u017eit\u00ed &#8211; modifikovan\u00e9 demo BlinkWithoutDelay.ino<\/p>\n<pre class=\"lang:cpp\" title=\"BlinkWithoutDelay.ino\">\/* Blink without Delay\r\n\r\n Turns on and off a light emitting diode(LED) connected to a digital\r\n pin, without using the delay() function.  This means that other code\r\n can run at the same time without being interrupted by the LED code.\r\n\r\n The circuit:\r\n * LED attached from pin 13 to ground.\r\n * Note: on most Arduinos, there is already an LED on the board\r\n that's attached to pin 13, so no hardware is needed for this example.\r\n \r\n created 2005\r\n by David A. Mellis\r\n modified 8 Feb 2010\r\n by Paul Stoffregen\r\n modified 11 Nov 2013\r\n by Scott Fitzgerald\r\n modified 5 Oct 2014\r\n by Pavel Brychta\r\n \r\n \r\n This example code is in the public domain.\r\n \r\n http:\/\/www.arduino.cc\/en\/Tutorial\/BlinkWithoutDelay\r\n *\/\r\n#include \"interval.h\"\r\n\r\n\/\/ constants won't change. Used here to set a pin number :\r\nconst int ledPin =  13;      \/\/ the number of the LED pin\r\n\r\n\/\/ Variables will change :\r\nint ledState = LOW;             \/\/ ledState used to set the LED\r\n\r\nInterval blink;\r\n\r\n\/\/ constants won't change :\r\nconst long blinkinterval = 1000;           \/\/ interval at which to blink (milliseconds)\r\n\r\nvoid setup() {\r\n  \/\/ set the digital pin as output:\r\n  pinMode(ledPin, OUTPUT);\r\n}\r\n\r\nvoid loop()\r\n{\r\n  \/\/ here is where you'd put code that needs to be running all the time.\r\n\r\n  if (blink.expired()) {\r\n    blink.set(blinkinterval); \/\/ set new interval period\r\n    \/\/ if the LED is off turn it on and vice-versa:\r\n    if (ledState == LOW)\r\n      ledState = HIGH;\r\n    else\r\n      ledState = LOW;\r\n\r\n    \/\/ set the LED with the ledState of the variable:\r\n    digitalWrite(ledPin, ledState);\r\n  }\r\n}\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Pokud to pova\u017euji za vhodn\u00e9, tak v n\u011bkter\u00fdch projektech pou\u017e\u00edv\u00e1m platformu Arduino. Koncepce programov\u00e9 konstrukce aplikace pro Arduino spo\u010d\u00edv\u00e1 ve dvou hlavn\u00edch metod\u00e1ch &#8211; setup() a loop(), ve kter\u00e9 program neust\u00e1le b\u011b\u017e\u00ed. Pro pohodln\u011bj\u0161\u00ed pr\u00e1ci s obsluhou periodick\u00fdch proces\u016f jsem napsal jednoduchou knihovnu, kter\u00e1 tyto \u00fakoly umo\u017e\u0148uje napsat velmi elegantn\u00edm zp\u016fsobem.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[3],"tags":[36],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-arduino"],"_links":{"self":[{"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=421"}],"version-history":[{"count":5,"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions"}],"predecessor-version":[{"id":427,"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions\/427"}],"wp:attachment":[{"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xpablo.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}