{"id":141,"date":"2021-07-11T17:04:24","date_gmt":"2021-07-11T17:04:24","guid":{"rendered":"http:\/\/imported-85"},"modified":"2021-07-11T17:04:24","modified_gmt":"2021-07-11T17:04:24","slug":"comandare-un-led-rgb-da-tastiera","status":"publish","type":"post","link":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/","title":{"rendered":"Comandare un LED RGB da tastiera"},"content":{"rendered":"<p>&nbsp;&nbsp; <span style=\"font-family: courier new, courier; font-size: 12pt;\">In questo progetto mediante il monitor seriale invieremo stringhe ad Arduino per cambiare il colore della luce emessa da un LED RGB.<\/span><\/p>\n<p><span style=\"font-family: courier new, courier; font-size: 12pt;\">Ci serviremo della funzione<\/span><\/p>\n<p><span style=\"font-family: courier new, courier; font-size: 12pt;\">&nbsp; <code>Serial.parseInt()<\/code><\/span><\/p>\n<p><span style=\"font-family: courier new, courier; font-size: 12pt;\">per rilevare da una stringa valori separati da un carattere non alfanumerico, che in genere \u00e8 una punteggiatura come una virgola, un punto; va bene anche uno spazio. <br \/>Questa funzione restituisce il primo numero intero valido (<em>di tipo long<\/em>) letto dal buffer seriale; vengono saltati i caratteri che non siano un numero intero o il segno meno.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/images\/Arduino\/comandare-un-led-rgb-da-tastiera\/Comandare_un_LED_RGB_da_tastiera_html_14c817ecf077dfb3.png\" alt=\"Comandare un LED RGB da tastiera html 14c817ecf077dfb3\" width=\"400\" height=\"323\" style=\"margin: 50px; float: left;\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 14pt;\"><strong><span style=\"font-family: courier new, courier; font-size: 12pt;\">Componenti<\/span><\/strong><\/span><\/p>\n<ul>\n<li><span style=\"font-family: courier new, courier; font-size: 12pt;\">LED RGB<\/span><\/li>\n<li><span style=\"font-family: courier new, courier; font-size: 12pt;\">3 resistenze 220 \u03a9<\/span><\/li>\n<li><span style=\"font-family: courier new, courier; font-size: 12pt;\">Fili di collegamento<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"font-family: courier new, courier; font-size: 14pt;\">Il codice<\/span><\/strong><\/p>\n<p><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">const int pinVerde = 9;<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">const int pinBlu = 10;<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">const int pinRosso = 11;<\/span><\/code><\/p>\n<p><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">void setup() {<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">  Serial.begin(9600);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">  pinMode(pinRosso, OUTPUT);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">  pinMode(pinVerde, OUTPUT);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">  pinMode(pinBlu, OUTPUT);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">}<\/span><\/code><\/p>\n<p><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">void loop() {<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">  while (Serial.available() &gt; 0) {<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    int rosso = Serial.parseInt(); \/\/ leggi il primo dato<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    int verde = Serial.parseInt(); \/\/ leggi il secondo dato<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    int blu = Serial.parseInt(); \/\/ leggi il terzo dato<\/span><\/code><\/p>\n<p><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    if (Serial.read() == '<br \/>\n') { \/\/ se la stringa \u00e8 esaurita<\/span><\/code><\/p>\n<p><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    \/* \/\/<strong>RGB ad anodo comune<\/strong><\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       rosso = 255 - constrain(rosso, 0, 255);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       verde = 255 - constrain(verde, 0, 255);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       blu = 255 - constrain(blu, 0, 255);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    *\/<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">      \/\/ RGB a catodo comune<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       rosso = constrain(rosso, 0, 255); \/\/ Nel caso si ecceda l\u2019intervallo (0,255)<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       verde = constrain(verde, 0, 255);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       blu = constrain(blu, 0, 255);<\/span><\/code><\/p>\n<p><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">      \/\/ configura il rosso, il verde, ed il blu sul LED RGB<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       analogWrite(pinRosso, rosso);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       analogWrite(pinVerde, verde);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">       analogWrite(pinBlu, blu);<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">    }  \/\/ end if<\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">  }    <code><span style=\"font-family: courier new, courier; font-size: 12pt;\">\/\/ end while<\/span><\/code><\/span><\/code><br \/><code><span style=\"font-family: courier new, courier; font-size: 12pt;\">}      <code><span style=\"font-family: courier new, courier; font-size: 12pt;\">\/\/ end loop<\/span><\/code><\/span><\/code><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p class=\"sdfootnote\"><a href=\"https:\/\/www.arduino.cc\/en\/Tutorial\/ReadASCIIString\">https:\/\/www.arduino.cc\/en\/Tutorial\/ReadASCIIString<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; In questo progetto mediante il monitor seriale invieremo stringhe ad Arduino per cambiare il colore della luce emessa da un LED RGB. Ci serviremo della funzione &nbsp; Serial.parseInt() per [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-giochi-di-luce-con-arduino"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Comandare un LED RGB da tastiera - PugliaSOS2.0<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Comandare un LED RGB da tastiera - PugliaSOS2.0\" \/>\n<meta property=\"og:description\" content=\"&nbsp;&nbsp; In questo progetto mediante il monitor seriale invieremo stringhe ad Arduino per cambiare il colore della luce emessa da un LED RGB. Ci serviremo della funzione &nbsp; Serial.parseInt() per [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/\" \/>\n<meta property=\"og:site_name\" content=\"PugliaSOS2.0\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-11T17:04:24+00:00\" \/>\n<meta name=\"author\" content=\"PugliaSOS\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"PugliaSOS\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/\"},\"author\":{\"name\":\"PugliaSOS\",\"@id\":\"http:\\\/\\\/130.110.14.181\\\/#\\\/schema\\\/person\\\/1e219b3d8de394c7d6969b52c116f336\"},\"headline\":\"Comandare un LED RGB da tastiera\",\"datePublished\":\"2021-07-11T17:04:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/\"},\"wordCount\":121,\"articleSection\":[\"Giochi di luce con Arduino\"],\"inLanguage\":\"it-IT\"},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/\",\"url\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/\",\"name\":\"Comandare un LED RGB da tastiera - PugliaSOS2.0\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/130.110.14.181\\\/#website\"},\"datePublished\":\"2021-07-11T17:04:24+00:00\",\"author\":{\"@id\":\"http:\\\/\\\/130.110.14.181\\\/#\\\/schema\\\/person\\\/1e219b3d8de394c7d6969b52c116f336\"},\"breadcrumb\":{\"@id\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/2021\\\/07\\\/11\\\/comandare-un-led-rgb-da-tastiera\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/130.110.14.181\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Comandare un LED RGB da tastiera\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/130.110.14.181\\\/#website\",\"url\":\"http:\\\/\\\/130.110.14.181\\\/\",\"name\":\"PugliaSOS2.0\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/130.110.14.181\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/130.110.14.181\\\/#\\\/schema\\\/person\\\/1e219b3d8de394c7d6969b52c116f336\",\"name\":\"PugliaSOS\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0f3d85b8e8409fc2c484f438be7de4caf93659f326adbb248e8a1ac5c2e16fd6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0f3d85b8e8409fc2c484f438be7de4caf93659f326adbb248e8a1ac5c2e16fd6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0f3d85b8e8409fc2c484f438be7de4caf93659f326adbb248e8a1ac5c2e16fd6?s=96&d=mm&r=g\",\"caption\":\"PugliaSOS\"},\"url\":\"http:\\\/\\\/130.110.14.181\\\/index.php\\\/author\\\/pugliasos\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Comandare un LED RGB da tastiera - PugliaSOS2.0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/","og_locale":"it_IT","og_type":"article","og_title":"Comandare un LED RGB da tastiera - PugliaSOS2.0","og_description":"&nbsp;&nbsp; In questo progetto mediante il monitor seriale invieremo stringhe ad Arduino per cambiare il colore della luce emessa da un LED RGB. Ci serviremo della funzione &nbsp; Serial.parseInt() per [&hellip;]","og_url":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/","og_site_name":"PugliaSOS2.0","article_published_time":"2021-07-11T17:04:24+00:00","author":"PugliaSOS","twitter_card":"summary_large_image","twitter_misc":{"Scritto da":"PugliaSOS","Tempo di lettura stimato":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/#article","isPartOf":{"@id":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/"},"author":{"name":"PugliaSOS","@id":"http:\/\/130.110.14.181\/#\/schema\/person\/1e219b3d8de394c7d6969b52c116f336"},"headline":"Comandare un LED RGB da tastiera","datePublished":"2021-07-11T17:04:24+00:00","mainEntityOfPage":{"@id":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/"},"wordCount":121,"articleSection":["Giochi di luce con Arduino"],"inLanguage":"it-IT"},{"@type":"WebPage","@id":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/","url":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/","name":"Comandare un LED RGB da tastiera - PugliaSOS2.0","isPartOf":{"@id":"http:\/\/130.110.14.181\/#website"},"datePublished":"2021-07-11T17:04:24+00:00","author":{"@id":"http:\/\/130.110.14.181\/#\/schema\/person\/1e219b3d8de394c7d6969b52c116f336"},"breadcrumb":{"@id":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/130.110.14.181\/index.php\/2021\/07\/11\/comandare-un-led-rgb-da-tastiera\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/130.110.14.181\/"},{"@type":"ListItem","position":2,"name":"Comandare un LED RGB da tastiera"}]},{"@type":"WebSite","@id":"http:\/\/130.110.14.181\/#website","url":"http:\/\/130.110.14.181\/","name":"PugliaSOS2.0","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/130.110.14.181\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"http:\/\/130.110.14.181\/#\/schema\/person\/1e219b3d8de394c7d6969b52c116f336","name":"PugliaSOS","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/secure.gravatar.com\/avatar\/0f3d85b8e8409fc2c484f438be7de4caf93659f326adbb248e8a1ac5c2e16fd6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0f3d85b8e8409fc2c484f438be7de4caf93659f326adbb248e8a1ac5c2e16fd6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0f3d85b8e8409fc2c484f438be7de4caf93659f326adbb248e8a1ac5c2e16fd6?s=96&d=mm&r=g","caption":"PugliaSOS"},"url":"http:\/\/130.110.14.181\/index.php\/author\/pugliasos\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":0,"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.110.14.181\/index.php\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}