{"id":6707,"date":"2021-12-22T04:08:36","date_gmt":"2021-12-22T04:08:36","guid":{"rendered":"https:\/\/www.qec.tw\/?p=6707"},"modified":"2021-12-28T09:26:12","modified_gmt":"2021-12-28T09:26:12","slug":"constants","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/ja\/86duino-reference\/constants\/","title":{"rendered":"\u5b9a\u6570"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[Constants]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Constants are predefined expressions in the Arduino language. They are used to make the programs easier to read. We classify constants in groups.<\/p>\n\n\n<hr \/>\n\n\n<h2 class=\"wp-block-heading\">Defining Logical Levels, true and false (Boolean Constants)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are two constants used to represent truth and falsity in the 86Duino language:&nbsp;<code>true<\/code>, and&nbsp;<code>false<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">false<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>false<\/code>&nbsp;is the easier of the two to define. false is defined as 0 (zero).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">true<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">true is often said to be defined as 1, which is correct, but true has a wider definition. Any integer which is non-zero is true, in a Boolean sense. So -1, 2 and -200 are all defined as true, too, in a Boolean sense.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the&nbsp;<code>true<\/code>&nbsp;and&nbsp;<code>false<\/code>&nbsp;constants are typed in lowercase unlike HIGH, LOW, INPUT, &amp; OUTPUT.<\/p>\n\n\n<hr \/>\n\n\n<h2 class=\"wp-block-heading\">Defining Pin Levels, HIGH and LOW<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When reading or writing to a digital pin there are only two possible values a pin can take\/be-set-to:&nbsp;<code>HIGH<\/code>&nbsp;and&nbsp;<code>LOW<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>HIGH<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The meaning of HIGH (in reference to a pin) is somewhat different depending on whether a pin is set to an INPUT or OUTPUT. When a pin is configured as an INPUT with&nbsp;<code>pinMode()<\/code>, and read with&nbsp;<code>digitalRead()<\/code>, the processor will report HIGH if a voltage of 2.5 volts or more is present at the pin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a pin is configured to OUTPUT with&nbsp;<code>pinMode()<\/code>, and set to HIGH with&nbsp;<code>digitalWrite()<\/code>, the pin is at 3.3 volts. In this state it can source current, e.g. light an LED that is connected through a series resistor to ground, or to another pin configured as an output, and set to LOW.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>LOW<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT. When a pin is configured as an INPUT with&nbsp;<code>pinMode()<\/code>, and read with&nbsp;<code>digitalRead()<\/code>, the processor will report LOW if a voltage of 0.8 volts or less is present at the pin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a pin is configured to OUTPUT with&nbsp;<code>pinMode()<\/code>, and set to LOW with&nbsp;<code>digitalWrite()<\/code>, the pin is at 0 volts. In this state it can sink current, e.g. light an LED that is connected through a series resistor to, +5 volts, or to another pin configured as an output, and set to HIGH.<\/p>\n\n\n<hr \/>\n\n\n<h2 class=\"wp-block-heading\">Defining Digital Pins, INPUT, INPUT_PULLUP, and OUTPUT<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Digital pins can be used as&nbsp;<code>INPUT<\/code>,&nbsp;<code>INPUT_PULLUP<\/code>, or&nbsp;<code>OUTPUT<\/code>. Changing a pin with&nbsp;<code>pinMode()<\/code>&nbsp;changes the electrical behavior of the pin.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pins Configured as INPUT<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">86Duino pins configured as&nbsp;<code>INPUT<\/code>&nbsp;with&nbsp;<code>pinMode()<\/code>&nbsp;are said to be in a high-impedance state. Pins configured as INPUT make extremely small demands on the circuit that they are sampling, equivalent to a high-impedance series resistor (&gt;&gt; 10 Megohms) in front of the pin. This makes them useful for reading a sensor, but not powering an LED.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have your pin configured as an INPUT, you will want the pin to have a reference to ground, often accomplished with a pull-down resistor (a resistor going to ground) as described in Arduino\u2019s&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Tutorial\/DigitalReadSerial\" target=\"_blank\" rel=\"noopener\">Digital Read Serial<\/a>&nbsp;tutorial.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pins Configured as INPUT_PULLUP<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The CPU of the 86Duino has internal pull-up resistors (resistors that connect to power internally) of 75 kilo ohms. If you prefer to use these instead of external pull-down resistors, you can use the&nbsp;<code>INPUT_PULLUP<\/code>&nbsp;argument in&nbsp;<code>pinMode()<\/code>. This effectively inverts the behavior, where HIGH means the sensor is off, and LOW means the sensor is on. See Arduino\u2019s&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Tutorial\/InputPullupSerial\" target=\"_blank\" rel=\"noopener\">Input Pullup Serial<\/a>&nbsp;tutorial for an example of this in use.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pins Configured as OUTPUT<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Pins configured as&nbsp;<code>OUTPUT<\/code>&nbsp;with&nbsp;<code>pinMode()<\/code>&nbsp;are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. 86Duino pins can source (provide positive current) or sink (provide negative current) up to 16 mA (milliamps) of current to other devices\/circuits. This makes them useful for powering LED\u2019s but useless for reading sensors. Pins configured as outputs can also be damaged or destroyed if short circuited to either ground or 5 volt power rails. The amount of current provided by an 86Duino pin is also not enough to power most relays or motors, and some interface circuitry will be required.<\/p>\n\n\n<hr \/>\n\n\n<h2 class=\"wp-block-heading\">See also<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>[Language]&nbsp;pinMode()<\/li><li>[Language]&nbsp;Integer Constants<\/li><li>[Language]&nbsp;boolean variables<\/li><\/ul>\n\n\n<hr \/>\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.qec.tw\/86duino\/86duino-language-reference\/\">Language Reference Home<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The text of the 86Duino reference is a modification of&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Reference\/HomePage\" target=\"_blank\" rel=\"noopener\">the Arduino reference<\/a>&nbsp;and is licensed under a&nbsp;<a href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/\" target=\"_blank\" rel=\"noopener\">Creative Commons Attribution-ShareAlike 3.0 License<\/a>. Code samples in the reference are released into the public domain.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Constants] Description Constants are predefined expressions in the Arduino language. They are used to make the programs easier to read. We classify constants in groups. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6708,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[195],"tags":[162],"class_list":["post-6707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-86duino-reference","tag-86duino"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/6707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/comments?post=6707"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/6707\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media\/6708"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media?parent=6707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/categories?post=6707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/tags?post=6707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}