{"id":3246,"date":"2017-06-23T11:56:39","date_gmt":"2017-06-23T08:56:39","guid":{"rendered":"http:\/\/roboromania.ro\/?p=3246"},"modified":"2017-08-02T09:59:18","modified_gmt":"2017-08-02T06:59:18","slug":"led-onoff-comandat-la-bataie-din-palme-claps-pentru-incepatori","status":"publish","type":"post","link":"https:\/\/roboromania.ro\/?p=3246","title":{"rendered":"LED ON\/OFF comandat la b\u0103taie din palme &#8222;CLAPS&#8221; &#8211; pentru \u00eencep\u0103tori"},"content":{"rendered":"<p><span style=\"color: #0000ff;\">LED ON\/OFF comandat la b\u0103taie din palme &#8222;CLAPS&#8221;<\/span><\/p>\n<p><span style=\"color: #0000ff;\">Pute\u021bi s\u0103 aprinde\u021bi\/stinge\u021bi lumina din camera la o b\u0103taie din palme<\/span><\/p>\n<p>Avem nevoie de :<\/p>\n<pre class=\"product_title entry-title\"><a href=\"http:\/\/roboromania.ro\/produs\/placa-de-dezvoltare-uno-r3-placa-de-dezvoltare-compatibila-arduino\/\" target=\"_blank\">Plac\u0103 de dezvoltare UNO R3<\/a> (sau oricare)\r\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-754\" src=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2015\/08\/Uno-roboromania-fata.jpg\" alt=\"Uno-roboromania-fata\" width=\"200\" height=\"132\" \/>\r\n\r\n<\/pre>\n<pre class=\"product_title entry-title\"><a href=\"http:\/\/roboromania.ro\/produs\/modulul-senzor-de-detectare-a-sunetului-compatibil-arduino\/\" target=\"_blank\">Modulul senzor de detectare a sunetului<\/a>\r\n\r\n<a href=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2016\/01\/Modulul-senzor-detectare-sunet-roboromania-.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1147\" src=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2016\/01\/Modulul-senzor-detectare-sunet-roboromania-.jpg\" alt=\"Modulul-senzor-detectare-sunet-roboromania\" width=\"200\" height=\"156\" \/><\/a>\r\nCa LED \u00eel vom folosi pe cel de la placa de dezvoltare : Led13 (sau oricare LED montat \u00een \"pin\" cu o rezistent\u0103 \u00een serie de 1k))\r\n\r\nCodul : CLAPS\r\n\/\/-------------------------------\r\nconst int sound_pin = 2;\r\nconst int led_pin = 13;\r\nconst unsigned long min_time_distance_between_signals = 100UL;\r\nconst unsigned long max_time_distance_between_signals = 500UL;\r\n\r\nconst unsigned long delay_after_triggered = 2000UL;\r\n\r\nbool led_state;\r\nunsigned long last_time_since_clap;\r\nunsigned long last_action_time;\r\n\r\nvoid setup ()\r\n{\r\n Serial.begin(9600); \r\n pinMode (sound_pin, INPUT) ; \r\n pinMode(led_pin, OUTPUT);\r\n digitalWrite(led_pin, LOW);\r\n\r\n led_state = false;\r\n last_action_time = 0;\r\n last_time_since_clap = 0;\r\n}\r\n\r\nvoid update_state(bool new_state, unsigned long current_time) {\r\n led_state = new_state;\r\n last_action_time = current_time;\r\n digitalWrite(led_pin, led_state ? HIGH : LOW);\r\n Serial.print(\"state = \");\r\n Serial.println(led_state);\r\n}\r\n\r\nvoid loop () {\r\n int sound_detected_state = digitalRead(sound_pin);\r\n\r\n unsigned long current_time = millis();\r\n unsigned long delta_time_since_last_action = current_time - last_action_time;\r\n\r\n if ((delta_time_since_last_action &gt; delay_after_triggered) &amp;&amp; ( sound_detected_state == HIGH )) {\r\n if (!led_state) {\r\n unsigned long current_delta_time_between_signals = current_time - last_time_since_clap;\r\n if (current_delta_time_between_signals &gt; max_time_distance_between_signals) {\r\n last_time_since_clap = current_time;\r\n } else if (current_delta_time_between_signals &gt; min_time_distance_between_signals) {\r\n update_state(true, current_time);\r\n }\r\n } else {\r\n update_state(false, current_time);\r\n }\r\n }\r\n}<\/pre>\n<pre class=\"product_title entry-title\">\/\/-------------------------------\r\n\r\n<\/pre>\n<p><span style=\"color: #0000ff;\">Succes !<\/span><\/p>\n<p>Colectivul Roboromania<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LED ON\/OFF comandat la b\u0103taie din palme &#8222;CLAPS&#8221; Pute\u021bi s\u0103 aprinde\u021bi\/stinge\u021bi lumina din camera la o b\u0103taie din palme Avem nevoie de : Plac\u0103 de dezvoltare UNO R3 (sau oricare) Modulul senzor de detectare a sunetului Ca LED \u00eel vom folosi pe cel de la placa de dezvoltare : Led13 (sau oricare LED montat \u00een [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[176],"tags":[],"class_list":["post-3246","post","type-post","status-publish","format-standard","hentry","category-tutoriale-arduino"],"_links":{"self":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts\/3246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3246"}],"version-history":[{"count":4,"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts\/3246\/revisions"}],"predecessor-version":[{"id":3409,"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts\/3246\/revisions\/3409"}],"wp:attachment":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}