{"id":1596,"date":"2021-10-12T14:04:28","date_gmt":"2021-10-12T05:04:28","guid":{"rendered":"http:\/\/leenux.kr\/?p=1596"},"modified":"2021-10-12T14:24:07","modified_gmt":"2021-10-12T05:24:07","slug":"arduino-if-else-%ec%82%bc%ed%95%ad%ec%97%b0%ec%82%b0%ec%9e%90","status":"publish","type":"post","link":"https:\/\/leenux.kr\/?p=1596","title":{"rendered":"[Arduino] if, else, switch, \uc0bc\ud56d\uc5f0\uc0b0\uc790"},"content":{"rendered":"\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p class=\"has-text-color has-medium-font-size has-very-dark-gray-color\"><strong>if, else \ubb38<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int led_pin = 12;\nint a, b, c = 0;\nchar input;\n\nvoid setup() {\n  \/\/ put your setup code here, to run once:\n  pinMode(led_pin, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/ put your main code here, to run repeatedly:\n  while (Serial.available() > 0)\n  {\n    input = Serial.read();\n  }\n\n  if (input == 1) {     \/\/ input\uc774 1\uc774\uba74\n    digitalWrite(led_pin, HIGH);    \/\/ LED\ub97c ON \uc2dc\ud0b4\n  } \n  else if (input == 2) {      \/\/ input\uc774 2\uc774\uba74\n    digitalWrite(led_pin, LOW);     \/\/ LED\ub97c OFF \uc2dc\ud0b4\n  } \n  else {        \/\/ input\uc774 1,2\uac00 \uc544\ub2c8\uba74,\n    digitalWrite(led_pin, HIGH);\n    delay(1000);\n    digitalWrite(led_pin, LOW);\n    delay(1000);                \/\/ LED\ub97c 1\ucd08 \uac04\uaca9\uc73c\ub85c ON\/OFF \ubc18\ubcf5\ud568\n }\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p class=\"has-text-color has-medium-font-size has-very-dark-gray-color\"><strong>switch \ubb38<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int led_pin = 12;\nint a, b, c = 0;\nchar input;\n\nvoid setup() {\n  \/\/ put your setup code here, to run once:\n  pinMode(led_pin, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/ put your main code here, to run repeatedly:\n  while (Serial.available() > 0)\n  {\n    input = Serial.read();\n  }\n\n  switch(input){\n    case 1:{\n      digitalWrite(led_pin, HIGH);    \/\/ LED\ub97c ON \uc2dc\ud0b4\n      break;\n    }\n    case 2:{\n      digitalWrite(led_pin, LOW);     \/\/ LED\ub97c OFF \uc2dc\ud0b4\n      break;\n    }\n    default:{\n      digitalWrite(led_pin, HIGH);\n      delay(1000);\n      digitalWrite(led_pin, LOW);\n      delay(1000);\n      break; \n    }\n  }\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p class=\"has-text-color has-medium-font-size has-very-dark-gray-color\"><strong>\uc0bc\ud56d\uc5f0\uc0b0\uc790\ub294 \uc138 \uac1c\uc758\u00a0\ud53c\uc5f0\uc0b0\uc790\ub97c \ucde8\ud560 \uc218 \uc788\ub294 \uc720\uc77c\ud55c \uc5f0\uc0b0\uc790\uc785\ub2c8\ub2e4.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 1 == 1 ? 1 : 0;\n\n\/\/ 1 == 1\ub294 \uc9c4\uc2e4\uc774\uae30 \ub584\ubb38\uc5d0 a\ubcc0\uc218\uc758 \uac12\uc740 1 \ub418\uace0 \ub9cc\uc57d\uc5d0 \uac70\uc9d3\uc774\uc600\ub2e4\uba74 0\uac12\uc774 \ub41c\ub2e4. <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/leenux.kro.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-1024x576.png\" alt=\"\" class=\"wp-image-1599\" srcset=\"https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-1024x576.png 1024w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-300x169.png 300w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-768x432.png 768w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-830x467.png 830w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-230x129.png 230w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-350x197.png 350w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790-480x270.png 480w, https:\/\/leenux.kr\/wp-content\/uploads\/2021\/10\/\uc0bc\ud56d\uc5f0\uc0b0\uc790.png 1152w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>[Arduino] if, else, \uc0bc\ud56d\uc5f0\uc0b0\uc790<\/p>\n","protected":false},"author":1,"featured_media":1553,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[95],"tags":[],"_links":{"self":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts\/1596"}],"collection":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1596"}],"version-history":[{"count":4,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts\/1596\/revisions"}],"predecessor-version":[{"id":1601,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/posts\/1596\/revisions\/1601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=\/wp\/v2\/media\/1553"}],"wp:attachment":[{"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leenux.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}