{"id":6914,"date":"2021-12-23T06:04:32","date_gmt":"2021-12-23T06:04:32","guid":{"rendered":"https:\/\/www.qec.tw\/?p=6914"},"modified":"2021-12-28T09:26:10","modified_gmt":"2021-12-28T09:26:10","slug":"analogread","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/ja\/86duino-reference\/analogread\/","title":{"rendered":"analogRead()"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[Analog I\/O]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Reads the value from the specified analog pin. The 86Duino boards contain several channels (6 channels on the Zero and EduCake, 7 on the One), 11-bit analog to digital converter. This means that it will map input voltages between 0 and 3.3 volts into integer values between 0 and 1023 (or 2047 by calling&nbsp;<code>analogReadResolution()<\/code>&nbsp;to set the 11-bit resolution). This yields a resolution between readings of: 3.3 volts \/ 1024 units or, .0032 volts (3.2 mV) per unit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It takes about 15 microseconds (0.000015 s) to read an analog input, so the maximum reading rate is about 66,666 times a second.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, there is no any analog pin on 86Duino PLC, the value getting from analogRead() is not available.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>analogRead(pin)<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Parameters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>pin<\/code>: the number of the analog input pin to read from (0 to 5 on the Zero and EduCake, 0 to 6 on the One)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Returns<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">int (0 to 1023 by default)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Note<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the analog input pin is not connected to anything, the value returned by&nbsp;<code>analogRead()<\/code>&nbsp;will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On 86Duino boards, the maximum input voltage of the analog to digital converter is 3.3V and so the user must take care the input voltage on every analog pin. If there is a voltage &gt; 3.3V appearing on any analog pin, the whole analog to digital converter will behave strangely and even be destroyed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example Code<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>int analogPin = 3;     \/\/ potentiometer wiper (middle terminal) connected to analog pin 3\n                       \/\/ outside leads to ground and +5V\nint val = 0;           \/\/ variable to store the value read\n \nvoid setup()\n{\n  Serial.begin(9600);          \/\/  setup serial\n}\n \nvoid loop()\n{\n  val = analogRead(analogPin);    \/\/ read the input pin\n  Serial.println(val);            \/\/ debug value\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">See also<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>[Language]\u00a0<a href=\"https:\/\/www.qec.tw\/86duino-reference\/analogreadresolution\/\">analogReadResolution<\/a>()<\/li><li>[Example]\u00a0<a href=\"http:\/\/arduino.cc\/en\/Tutorial\/AnalogInputPins\" target=\"_blank\" rel=\"noopener\">Tutorial: Analog Input Pins<\/a><\/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>[Analog I\/O] Description Reads the value from the specified analog pin. The 86Duino boards contain several channels (6 channels on the Zero and EduCake, 7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6915,"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-6914","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\/6914","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=6914"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/6914\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media\/6915"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media?parent=6914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/categories?post=6914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/tags?post=6914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}