{"id":812,"date":"2016-03-01T12:32:18","date_gmt":"2016-03-01T04:32:18","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=812"},"modified":"2016-03-01T12:32:18","modified_gmt":"2016-03-01T04:32:18","slug":"arduino-fade-led-%e5%bf%bd%e6%98%8e%e5%bf%bd%e6%9a%97%e7%9a%84-led-%e7%87%88","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=812","title":{"rendered":"[ Arduino ] \u2013 Fade LED \u5ffd\u660e\u5ffd\u6697\u7684 LED \u71c8"},"content":{"rendered":"<p>\t\t\t\t\u958b\u555f fade \u7bc4\u4f8b\u7a0b\u5f0f<br \/>\n<a href=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/fade.png\" rel=\"attachment wp-att-813\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/fade.png\" alt=\"fade\" width=\"853\" height=\"738\" class=\"alignleft size-full wp-image-813\" srcset=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/fade.png 853w, https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/fade-300x260.png 300w, https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/fade-768x664.png 768w\" sizes=\"auto, (max-width: 853px) 100vw, 853px\" \/><\/a><br \/>\n\u7d05\u8272\u6b63\u6975 \u63d2\u5165 \u8173\u4f4d 9 \u85cd\u8272 \u8ca0\u6975 \u63d2\u5165 GND\u63a5\u5730\u7dda<br \/>\n<a href=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/IMG_20160301_120030-scaled-1.jpg\" rel=\"attachment wp-att-815\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/IMG_20160301_120030-1024x544.jpg\" alt=\"IMG_20160301_120030\" width=\"1024\" height=\"544\" class=\"alignleft size-large wp-image-815\" \/><\/a><br \/>\n\u9eb5\u5305\u677f\u4e0a \u7d05\u8272\u63d2\u5165\u6b63\u6975 \u85cd\u8272 \u63d2\u5165 \u8ca0\u6975 LED \u9577\u8173\u4f4d\u63d2\u5165\u6b63\u6975 \u77ed\u8173\u4f4d\u63d2\u5165\u8ca0\u6975<br \/>\n<a href=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/IMG_20160301_120038.jpg\" rel=\"attachment wp-att-816\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2016\/03\/IMG_20160301_120038-1024x818.jpg\" alt=\"IMG_20160301_120038\" width=\"1024\" height=\"818\" class=\"alignleft size-large wp-image-816\" \/><\/a><br \/>\n\u7a0b\u5f0f\u90e8\u4efd<br \/>\n[java]<br \/>\n\/*<br \/>\n Fade<br \/>\n This example shows how to fade an LED on pin 9<br \/>\n using the analogWrite() function.<br \/>\n The analogWrite() function uses PWM, so if<br \/>\n you want to change the pin you&#8217;re using, be<br \/>\n sure to use another PWM capable pin. On most<br \/>\n Arduino, the PWM pins are identified with<br \/>\n a &quot;~&quot; sign, like ~3, ~5, ~6, ~9, ~10 and ~11.<br \/>\n This example code is in the public domain.<br \/>\n *\/<br \/>\nint led = 9;           \/\/ the PWM pin the LED is attached to<br \/>\nint brightness = 0;    \/\/ how bright the LED is<br \/>\nint fadeAmount = 5;    \/\/ how many points to fade the LED by \u8acb\u8a66\u8457\u4fee\u6539\u9019\u500b\u503c<br \/>\n\/\/ the setup routine runs once when you press reset:<br \/>\nvoid setup() {<br \/>\n  \/\/ declare pin 9 to be an output:<br \/>\n  pinMode(led, OUTPUT);<br \/>\n}<br \/>\n\/\/ the loop routine runs over and over again forever:<br \/>\nvoid loop() {<br \/>\n  \/\/ set the brightness of pin 9:<br \/>\n  analogWrite(led, brightness);<br \/>\n  \/\/ change the brightness for next time through the loop:<br \/>\n  brightness = brightness + fadeAmount;<br \/>\n  \/\/ reverse the direction of the fading at the ends of the fade:<br \/>\n  if (brightness == 0 || brightness == 255) {<br \/>\n    fadeAmount = -fadeAmount ;<br \/>\n  }<br \/>\n  \/\/ wait for 30 milliseconds to see the dimming effect<br \/>\n  delay(30);<br \/>\n}<br \/>\n[\/java]<br \/>\n\u57f7\u884c\u5f71\u7247<br \/>\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/tGs9nl_ET_0\" frameborder=\"0\" allowfullscreen><\/iframe>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u958b\u555f fade \u7bc4\u4f8b\u7a0b\u5f0f \u7d05\u8272\u6b63\u6975 \u63d2\u5165 \u8173\u4f4d 9&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[250],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-fade"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=812"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}