{"id":819,"date":"2016-03-01T12:45:56","date_gmt":"2016-03-01T04:45:56","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=819"},"modified":"2016-03-01T12:45:56","modified_gmt":"2016-03-01T04:45:56","slug":"arduino-switch-led-%e5%b9%ab-led-%e7%87%88%e5%8a%a0%e4%b8%8a%e9%96%8b%e9%97%9c","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=819","title":{"rendered":"[ Arduino ] \u2013 Switch LED \u5e6b LED \u71c8\u52a0\u4e0a\u958b\u95dc"},"content":{"rendered":"<p>\t\t\t\t[java]<br \/>\nconst int buttonPin = 2;     \/\/ the number of the pushbutton pin<br \/>\nconst int ledPin =  13;      \/\/ the number of the LED pin<br \/>\nstatic int ledStatus;<br \/>\n\/\/ variables will change:<br \/>\nint buttonState = 0;         \/\/ variable for reading the pushbutton status<br \/>\nvoid setup() {<br \/>\n  \/\/ initialize the LED pin as an output:<br \/>\n  pinMode(ledPin, OUTPUT);<br \/>\n  \/\/ initialize the pushbutton pin as an input:<br \/>\n  pinMode(buttonPin, INPUT);<br \/>\n   ledStatus = LOW;<br \/>\n}<br \/>\nvoid loop(){<br \/>\n  \/\/ read the state of the pushbutton value:<br \/>\n  buttonState = digitalRead(buttonPin);<br \/>\n  \/\/ check if the pushbutton is pressed.<br \/>\n  \/\/ if it is, the buttonState is HIGH:<br \/>\n  if (buttonState == HIGH) {<br \/>\n    \/\/ turn LED on:<br \/>\n    ledStatus = ledStatus == HIGH ? LOW : HIGH;<br \/>\n    delay(300);<br \/>\n    digitalWrite(ledPin, ledStatus);<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<br \/>\n\u53c3\u8003\u7db2\u5740<br \/>\n<a href=\"http:\/\/yehnan.blogspot.tw\/2012\/02\/arduinoled.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/yehnan.blogspot.tw\/2012\/02\/arduinoled.html<\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[java] const int buttonPi&#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":[],"class_list":["post-819","post","type-post","status-publish","format-standard","hentry","category-arduino"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/819","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=819"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/819\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}