{"id":419,"date":"2016-12-01T15:41:03","date_gmt":"2016-12-01T07:41:03","guid":{"rendered":"http:\/\/www.lanchbury.id.au\/?p=419"},"modified":"2016-12-01T15:44:18","modified_gmt":"2016-12-01T07:44:18","slug":"arduino-functions-with-variable-digitalwrite","status":"publish","type":"post","link":"https:\/\/www.lanchbury.au\/?p=419","title":{"rendered":"Arduino Functions with Variable DigitalWrite"},"content":{"rendered":"<p>I feel like I&#8217;ve been looking for a couple of years for this solution and could never find it.  Well I worked it out for myself so I thought I should post it so the answer can be found for others as it really does seem to be complete undocumented online.<\/p>\n<p><code>int redLed = 13;                  \/\/ assigning redLed with the onboard LED<br \/>\nint blueLed = 12;                 \/\/ assigning blueLed with offboard LED with resister<\/p>\n<p>void setup(){<br \/>\n  pinMode(redLed , OUTPUT);      \/\/ set these pin as outputs for digital writes<br \/>\n  pinMode(blueLed , OUTPUT);     \/\/ set these pin as outputs for digital writes<br \/>\n}<\/p>\n<p>void loop(){<br \/>\n  ledBlinking(redLed, 6, 500, 100);       \/\/ run function targeting the red LED<br \/>\n  ledBlinking(blueLed, 12, 100, 100);     \/\/ run function targeting the blue LED<br \/>\n}<\/p>\n<p>void ledBlinking(word led, int amount, int timeOn, int timeOff){    \/\/ set the variables used between loop and function<br \/>\n  for ( int i=1; i<=amount; i=i+1 ) {       \/\/ for each i in amount run the below\n    digitalWrite(led, HIGH);            \/\/ bring the chosen pin high\n    delay(timeOn);                          \/\/ wait the LED time on\n    digitalWrite(led, LOW);             \/\/ bring the chosen pin low\n    delay(timeOff);                         \/\/ wait the LED time off\n  }                                         \/\/ loop back to i counter until over\n}<\/code><\/p>\n<p>So hopefully you see what I'm doing here.  I'm telling the function in void loop to use the pin redLed and blueLed with a word (not a string) variable.  The rest are simple integers holding the amount of flashes, and how long to hold them on and off for.<\/p>\n<p>Simple when you know how, now on to the bigger project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I feel like I&#8217;ve been looking for a couple of years for this solution and could never find it. Well I worked it out for myself so I thought I should post it so the answer can be found for others as it really does seem to be complete undocumented online. int redLed = 13; &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/www.lanchbury.au\/?p=419\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[17,20,18,21,22,19,23],"class_list":["post-419","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-arduino","tag-digitalwrite","tag-functions","tag-pin","tag-string","tag-variable","tag-word","item-wrap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7tC7P-6L","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=419"}],"version-history":[{"count":3,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts\/419\/revisions"}],"predecessor-version":[{"id":422,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts\/419\/revisions\/422"}],"wp:attachment":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}