<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아두이노는 스케치에 저장된 변수와, 문자 열등의 데이터를 아두이노 초기화 시 Flash memory에서 읽어&nbsp; SRAM에 저장하여 코드 실행 시 빠르게 처리될 수 있도록 하고 있다. 하지만 아두이노 우노의 경우 SRAM의 크기가 2048 bytes로써 그렇게 크다고 할 수 없다. 통신용 라이브러리의 경우 보통 300 ~ 500 bytes 정도의 통신용 버퍼가 필요하고 그 버퍼로 SRAM을 사용한다고 한다. 비단 통신용 라이브러리뿐만 아니라 각 라이브러리들에는 눈에 보이지 않는 라이브러리 내부 변수들이 있고 이러한 변수들 역시 SRAM의 공간을 차지하게 된다. 사용하는 라이브러리가 많아질수록 SRAM의 여유 공간은 줄어들고 코드 실행에 필요한 충분한 메모리 여유 공간을 확보하지 못한다면 메모리 에러(stack error) 또는 무한 리부팅을 경험하게 된다. 이러한 오류 발생을 방지하기 위해서는 스케치를 작성할 때 최대한 메모리를 확보하도록 코드를 짜주어야 하는데 여러 방법 중에 PROGMEM과 F() 매크로를 사용하여 상수(const, 고정된 값)로써 읽기만 하는 데이터는 Flash memory에서 바로 읽도록 하는 게 가장 손쉬운 방법이라 할 수 있다.&nbsp;<br /><br />대표적인&nbsp;상수로&nbsp;문자열(또는&nbsp;스트링)을&nbsp;꼽을&nbsp;수&nbsp;있고&nbsp;이&nbsp;문자열을&nbsp;PROGMEM과&nbsp;F()&nbsp;매크로를&nbsp;사용하여&nbsp;Flash&nbsp;memory에서&nbsp;바로&nbsp;읽도록 할&nbsp;때&nbsp;SRAM의&nbsp;공간 확보에&nbsp;있어&nbsp;그&nbsp;효과가&nbsp;가장&nbsp;좋다고&nbsp;말할&nbsp;수&nbsp;있다.&nbsp;&nbsp;<br /><br />Serial.print("문자열')에&nbsp;사용하는&nbsp;문자열도&nbsp;SRAM에&nbsp;저장되었다가&nbsp;시리얼&nbsp;모니터에&nbsp;메시지를&nbsp;출력할&nbsp;때&nbsp;사용되게&nbsp;된다.&nbsp;이렇게&nbsp;반복적이지&nbsp;않게&nbsp;어느&nbsp;한&nbsp;코드에서만&nbsp;실행되는&nbsp;문자열의&nbsp;경우에는&nbsp;F()&nbsp;매크로를&nbsp;사용하여&nbsp;Serial.print(F("문자열"))로&nbsp;처리를&nbsp;해주면&nbsp;간단하게&nbsp;SRAM의&nbsp;공간을&nbsp;절약할&nbsp;수&nbsp;있게 된다.&nbsp;&nbsp;</p>
<table border="1" style="color: #000000; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; width: 6420px; border-style: solid; border-color: #99cefa; background-color: #f6f9fd;">
   <tbody>
      <tr>
         <td style="width: 6398px; padding: 10px;">
            <p>Serial.print(F("Write&nbsp;something&nbsp;on&nbsp;the&nbsp;Serial&nbsp;Monitor&nbsp;that&nbsp;is&nbsp;stored&nbsp;in&nbsp;FLASH"));&nbsp;<br />Serial.print((const&nbsp;PROGMEM&nbsp;char&nbsp;*)("Write&nbsp;something&nbsp;on&nbsp;the&nbsp;Serial&nbsp;Monitor&nbsp;that&nbsp;is&nbsp;stored&nbsp;in&nbsp;FLASH"));</p>
            </td>
         </tr>
      </tbody>
   </table>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">* 본래의&nbsp;pgmspace.h 라이브러리에는 "#define PSTR(s) ((const PROGMEM char *)(string))"가&nbsp;정의되어 있으나 아두이노 우노에서는 컴파일되지 않는다.(ESP8266 / ESP32 모듈에서는 사용 가능) 라이브러리에 통합하면서 F() 매크로와 중복된 기능이므로 생략됐을 수 있다.&nbsp;F() 매크로를 사용하는 경우와&nbsp;매크로를 사용하지 않고 PROGMEM 지시어 "(const PROGMEM char *)(string)"을 사용하는 것은 같다고 볼 수 있다.&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">서로&nbsp;다른&nbsp;코드에서&nbsp;반복적으로&nbsp;사용되는&nbsp;문자열(전역&nbsp;변수&nbsp;스트링)의&nbsp;경우&nbsp;PROGMEM을&nbsp;사용하여&nbsp;Flash&nbsp;memory에서&nbsp;바로&nbsp;읽도록&nbsp;하는 게&nbsp;효과적이다.&nbsp;또한&nbsp;PROGMEM의&nbsp;경우&nbsp;문자열뿐만 아니라&nbsp;다양한&nbsp;자료형에&nbsp;사용할&nbsp;수&nbsp;있다.&nbsp;&nbsp;<br /><br />PROGMEM을&nbsp;사용하기&nbsp;위해서는&nbsp;pgmspace.h&nbsp;라이브러리가&nbsp;필요했었지만&nbsp;아두이노&nbsp;IDE&nbsp;버전&nbsp;1.0부터&nbsp;자체&nbsp;라이브러리에&nbsp;포함되어&nbsp;있어&nbsp;따로&nbsp;라이브러리를&nbsp;불러올&nbsp;필요 없이&nbsp;스케치에서&nbsp;Flash&nbsp;memory에서&nbsp;바로&nbsp;읽을&nbsp;변수에&nbsp;변수&nbsp;수식어&nbsp;"PROGMEM"을&nbsp;사용하면&nbsp;된다.&nbsp;&nbsp;<br /><br />아래 페이지에서 pgmspace.h 라이브러리에 정의된 매크로와 함수들을 살펴볼 수 있다.&nbsp;&nbsp;<br /><a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html" style="color: #000000; text-decoration-line: none; transition: all 0.3s ease 0s;" target="_blank">https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html</a>&nbsp;<br /><br /></p>
<h3 data-ke-size="size23" style="font-size: 1.44em; font-weight: normal; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; background-color: #f1f1f1;">변수에&nbsp;PROGMEM&nbsp;수식어&nbsp;적용하기&nbsp;</h3>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아래 형식 중 하나를 사용하면 된다.</p>
<table border="1" style="color: #000000; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; width: 6420px; border-style: solid; border-color: #99cefa; background-color: #f6f9fd;">
   <tbody>
      <tr>
         <td style="width: 6398px; padding: 10px;">
            <p>const&nbsp;자료형&nbsp;변수이름[]&nbsp;PROGMEM&nbsp;=&nbsp;{};&nbsp;<br />const&nbsp;PROGMEM&nbsp;자료형&nbsp;변수이름[]&nbsp;=&nbsp;{};&nbsp;<br />const&nbsp;자료형&nbsp;PROGMEM&nbsp;변수이름[]&nbsp;=&nbsp;{};</p>
            </td>
         </tr>
      </tbody>
   </table>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">RPOGMEM을 전역 변수로 사용할 경우에는 상기의 형식을 바로 사용하면 되지만 로컬 변수로 사용할 경우에는 static 키워드로 정의를 해주어야 한다.&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><br />전역 변수로&nbsp;사용&nbsp;<br />const&nbsp;char&nbsp;str[]&nbsp;PROGMEM&nbsp;=&nbsp;"Hi,&nbsp;I&nbsp;would&nbsp;like&nbsp;to&nbsp;tell&nbsp;you&nbsp;a&nbsp;bit&nbsp;about&nbsp;myself.\n";&nbsp;<br />const PROGMEM char str[] = "Hi, I would like to tell you a bit about myself.\n";&nbsp;<br />const char PROGMEM str[] = "Hi, I would like to tell you a bit about myself.\n";&nbsp;<br /><br />로컬 변수로 사용 - 문자열의 경우 F() 매크로를 사용하면 간단하다.<br />const&nbsp;static&nbsp;char str[] PROGMEM = "Hi, I would like to tell you a bit about myself.\n" ;<br />const&nbsp;PROGMEM&nbsp;static&nbsp;char value[] =&nbsp;{ 36, -5, 0, -26, 99 };<br />const&nbsp;static&nbsp;char PROGMEM value[] =&nbsp;{ 36, -5, 0, -26, 99 };&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<div style="box-sizing: border-box; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1; position: relative; text-align: center; overflow: hidden; margin: auto;"><ins class="adsbygoogle" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-8269928309278636" data-ad-slot="7194013449" data-adsbygoogle-status="done" style="display: block; height: 0px;"><ins id="aswift_2_expand" style="display: inline-table; border: none; height: 0px; margin: 0px; padding: 0px; position: relative; visibility: visible; width: 879px; background-color: transparent;"><ins id="aswift_2_anchor" style="display: block; border: none; height: 0px; margin: 0px; padding: 0px; position: relative; visibility: visible; width: 879px; background-color: transparent; overflow: hidden; opacity: 0;"><iframe id="aswift_2" name="aswift_2" sandbox="allow-forms allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" width="879" height="200" frameborder="0" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-8269928309278636&amp;output=html&amp;h=200&amp;slotname=7194013449&amp;adk=2728018722&amp;adf=1597229448&amp;w=879&amp;fwrn=4&amp;lmt=1597036438&amp;rafmt=11&amp;psa=1&amp;guci=2.2.0.0.2.2.0.0&amp;format=879x200&amp;url=https%3A%2F%2Fpostpop.tistory.com%2F92%3Fcategory%3D744994&amp;flash=0&amp;wgl=1&amp;adsid=ChEI8L2--QUQ0tq16-2fjYqgARIqAO0FjTH2X4ovhdExS6bKOi7R9f0NygxK9IBK2VhOLFsQTLsM8j4Yinsr&amp;dt=1597036438387&amp;bpp=5&amp;bdt=411&amp;idt=369&amp;shv=r20200805&amp;cbv=r20190131&amp;ptt=9&amp;saldr=aa&amp;abxe=1&amp;cookie=ID%3D720ca2025ee5b318%3AT%3D1597021416%3AS%3DALNI_MbwB0RmCu8y8M7-tE67Lg-ncQLpkQ&amp;prev_fmts=0x0%2C300x250&amp;nras=1&amp;correlator=2969050074808&amp;frm=20&amp;pv=1&amp;ga_vid=190590715.1597021417&amp;ga_sid=1597036439&amp;ga_hid=919505124&amp;ga_fc=0&amp;iag=0&amp;icsg=8935813677056&amp;dssz=66&amp;mdo=0&amp;mso=0&amp;rplot=4&amp;u_tz=540&amp;u_his=19&amp;u_java=0&amp;u_h=1440&amp;u_w=2560&amp;u_ah=1400&amp;u_aw=2560&amp;u_cd=24&amp;u_nplug=3&amp;u_nmime=4&amp;adx=336&amp;ady=1573&amp;biw=1261&amp;bih=1287&amp;scr_x=0&amp;scr_y=0&amp;eid=42530558%2C42530560%2C21065725%2C21065727&amp;oid=3&amp;pvsid=2837138608314062&amp;pem=173&amp;ref=https%3A%2F%2Fpostpop.tistory.com%2F88%3Fcategory%3D744994&amp;rx=0&amp;eae=0&amp;fc=1920&amp;brdim=-7%2C40%2C-7%2C40%2C2560%2C40%2C1294%2C1407%2C1278%2C1287&amp;vis=1&amp;rsz=%7C%7CeoEbr%7C&amp;abl=CS&amp;pfx=0&amp;fu=8320&amp;bc=31&amp;jar=2020-08-10-04&amp;ifi=2&amp;uci=a!2&amp;btvi=1&amp;fsb=1&amp;xpc=G3XSF5TQ1h&amp;p=https%3A//postpop.tistory.com&amp;dtd=375" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" data-google-container-id="a!2" data-google-query-id="CJHVxKzwj-sCFUxYYAodH6cHaA" data-load-complete="true" style="max-width: 100%; left: 0px; position: absolute; top: 0px; border-width: 0px; border-style: initial; width: 879px; height: 200px;"></iframe></ins></ins></ins></div>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<h3 data-ke-size="size23" style="font-size: 1.44em; font-weight: normal; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; background-color: #f1f1f1;">PROGMEM 지시어로 저장된 문자열 출력하기&nbsp;&nbsp;</h3>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아두이노에서 PROGMEM 지시어로 저장된 문자열을 Serial.print("문자열") 함수를 통해 직접 출력하게 되면 읽을 수 없는 이상한 문자('⸮')가 출력되거나 아무것도 출력되지 않게 된다.</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">정상적으로 출력하기 위해서는 자료형 __FlashStringHelper를 이용해야 하고 이 자료형을 이용하여 아래처럼 매크로로 정의하여&nbsp;문자열을 출력하고자 하는 코드에 사용할 수 있다.&nbsp;&nbsp;&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">#define&nbsp;FV(s)&nbsp;((const&nbsp;__FlashStringHelper*)(s))</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아래 예제를 업로드하고 확인해 보자.</p>
<figure class="fileblock" style="margin: 28px auto 20px; max-width: 100%; clear: both; width: 470px; height: 71px; border: 1px solid rgb(233, 233, 233); position: relative; border-radius: 1px; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><a href="https://blog.kakaocdn.net/dn/bsRXaS/btqzOWJDrEN/HBmQBafOey93lhkqOaNxx0/progmem_string_print_test.ino?attach=1&amp;knm=tfile.ino" style="color: #000000; text-decoration-line: none; transition: all 0.3s ease 0s; display: block; height: 71px;" target="_blank">
      <div class="image" style="box-sizing: border-box; position: absolute; left: 0px; top: 0px; width: 30px; height: 30px; background-image: url(&quot;https://t1.daumcdn.net/tistory_admin/static/manage/post-editor/img_editor_content.svg&quot;); background-position: 0px 0px; margin: 21px 17px 20px 22px;">&nbsp;</div>
      <div class="desc" style="box-sizing: border-box; position: absolute; left: 70px; right: 60px; top: 0px; bottom: 0px;">
         <div class="filename" style="box-sizing: border-box; color: #333333; font-size: 14px; text-overflow: ellipsis; height: 20px; margin: 17px 0px 0px;"><span class="name" style="box-sizing: border-box; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 272px; height: 20px; display: block;">progmem_string_print_test.ino</span></div>
         <div class="size" style="box-sizing: border-box; font-family: &quot;Avenir Next&quot;, sans-serif; font-size: 12px; color: #777777; height: 16px; margin: 2px 0px 0px;">0.00MB</div>
         </div>
      </a></figure>
<pre id="code_1573959987604" class="c++ cpp arduino" data-ke-language="c++" data-ke-type="codeblock" style="overflow: auto hidden; padding: 10px; margin-top: 5px; margin-bottom: 5px; max-width: 100%; border: 1px solid rgb(221, 221, 221); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 21.6px; font-family: &quot;Lucida Console&quot;; background-color: #fafafa; border-radius: 3px;">
   <code class="hljs cpp" style="border: 1px solid rgb(238, 238, 238); background: rgb(40, 44, 52); color: #abb2bf; border-radius: 5px; padding: 0.5em; margin: 3px 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 17px; line-height: 1.3em; font-family: D2Coding, monospace; display: block; overflow-x: auto;"><span class="hljs-meta" style="box-sizing: border-box; color: #61aeee;">#<span class="hljs-meta-keyword" style="box-sizing: border-box;">define</span> FV(s) ((const __FlashStringHelper*)(s))</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">char</span> hello[] PROGMEM = <span class="hljs-string" style="box-sizing: border-box; color: #98c379;">"My Little Friend"</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">char</span> xyz[]  PROGMEM = {  <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 헥사표시 문자열</span><span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x53</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x61</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x79</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x48</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x65</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6f</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, 
  <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x74</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6f</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x4d</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x79</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x4c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x69</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x74</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x74</span>, 
  <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x65</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x46</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x72</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x69</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x65</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6e</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x64</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x00</span> 
}; 
<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span> byte xyz1[] PROGMEM = {  <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 헥사표시 문자열</span><span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x53</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x61</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x79</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x48</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x65</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6f</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, 
  <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x74</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6f</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x4d</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x79</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x4c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x69</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x74</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x74</span>, 
  <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6c</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x65</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x20</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x46</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x72</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x69</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x65</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x6e</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x64</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0x00</span> 
}; 
<span class="hljs-function" style="box-sizing: border-box; color: #61aeee;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: border-box;">setup</span><span class="hljs-params" style="box-sizing: border-box; color: #a6e22e;">()</span></span>{
  Serial.begin(<span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">9600</span>);
  Serial.println(F(<span class="hljs-string" style="box-sizing: border-box; color: #98c379;">"Hello World!"</span>));  <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// F() 매크로 사용</span>
  Serial.println(hello);              <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// PROGMEM 변수 직접 읽기 - 오류</span>
  Serial.println(FV(hello));          <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 정의된 FV(s) 매크로 이용 자료형 __FlashStringHelper로 변환</span>
  Serial.println((<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span> __FlashStringHelper *)hello); <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">//자료형 __FlashStringHelper 직접사용</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span> __FlashStringHelper *str = (<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span> __FlashStringHelper *)hello; <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// __FlashStringHelper 포인터 이용 저장</span>
  Serial.println(str);
  String str1 = (<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span> __FlashStringHelper *)hello; <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 스트링 변수에 저장</span>
  Serial.println(str1);
  Serial.println((<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span> __FlashStringHelper *)xyz); <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 자료형 char 문자 배열 출력</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">for</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">int</span> i = <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>; i &lt; <span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(xyz1); i++) {          <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 자료형 byte 문자 배열 출력</span>
    Serial.write(pgm_read_byte(xyz1 + i));
  }
}
<span class="hljs-function" style="box-sizing: border-box; color: #61aeee;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: border-box;">loop</span><span class="hljs-params" style="box-sizing: border-box; color: #a6e22e;">()</span></span>{
}</code>
   </pre>
<figure class="imageblock alignCenter" width="600" data-filename="progmem_string_error.jpg" data-origin-width="0" data-origin-height="0" style="margin: 0px auto 20px; max-width: 100%; clear: both; display: table; position: relative; text-align: center; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><span data-url="https://blog.kakaocdn.net/dn/cu3LAA/btqzPvENU17/Ua6SohsBeh3shKHExk5wRk/img.jpg" data-lightbox="lightbox" data-alt="" style="box-sizing: border-box; cursor: pointer;"><img src="https://blog.kakaocdn.net/dn/cu3LAA/btqzPvENU17/Ua6SohsBeh3shKHExk5wRk/img.jpg" srcset="https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fcu3LAA%2FbtqzPvENU17%2FUa6SohsBeh3shKHExk5wRk%2Fimg.jpg" width="600" data-filename="progmem_string_error.jpg" data-origin-width="0" data-origin-height="0" style="border: 0px; max-width: 100%; display: inline-block; margin: 0px; height: auto;" /></span></figure>
<h3 data-ke-size="size23" style="font-size: 1.44em; font-weight: normal; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; background-color: #f1f1f1;">문자열이 아닌 자료형에 따른 매크로의 사용방법&nbsp;</h3>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">avr/pgmspace.h 라이브러리에 정의된 매크로를 사용하여 코드를 작성해야 한다.&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;<br />const uint8_t&nbsp;value[] PROGMEM = { 28, 0, 255, 10, 117 };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 1 byte 자료형</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">const char&nbsp;value[] PROGMEM = { 36, -5, 0, -26, 99 };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 1 byte 자료형<br />const uint16_t&nbsp;value[] PROGMEM = { 65000, 32796, 16843, 10, 11234 };&nbsp; // 2 byte 자료형</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">const float&nbsp;value[] PROGMEM = { 19.0, 2.5, 22.56, -8.9, 3.5 };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// float 자료형(4 byte)</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<div style="box-sizing: border-box; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1; position: relative; text-align: center; overflow: hidden; margin: auto;"><ins class="kakao_ad_area" data-ad-unit="DAN-t4q6j60rbcqh" data-ad-width="728" data-ad-height="90" id="kakao_ad_pTLFId_1775" data-ad-rfseq="1" data-ad-status="done" data-ad-rendered="Y" data-ad-request-id="bb417e7b-3391-43a2-b9c8-36bbc44d3c27" data-ad-rfinterval="30" data-ad-bordercolor="unknown" data-ad-action="" data-ad-actioninterval="0" data-ad-refreshlimit="0" data-ad-noadmaxcount="10" data-ad-noadseq="0" style="display: inline-block; text-decoration-line: none; min-width: 728px; min-height: 90px; width: 728px; height: 90px;">
      <div data-ad-creative-wrap="outer" style="box-sizing: border-box; overflow: hidden; position: relative; min-width: 728px; min-height: 90px; max-height: inherit;">
         <div data-ad-creative-wrap="inner" style="box-sizing: border-box; overflow: hidden; height: 90px;"><iframe frameborder="0" scrolling="no" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" id="adfit_frame_id_YrHngR_4060" name="adfit_frame_id_YrHngR_4060" style="max-width: 100%; min-width: 728px; width: 728px; min-height: 90px; height: 90px; display: block; border-width: 0px; border-style: initial; margin: 0px auto;"></iframe></div>
         </div>
      </ins></div>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">자료형에 따른 매크로&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">pgm_read_byte(address_short)&nbsp; &nbsp; &nbsp; &nbsp;//&nbsp;포인터 주소의 1 byte 값을 읽는 매크로<br />pgm_read_word(address_short)&nbsp; &nbsp; &nbsp;//&nbsp;포인터 주소의 2 byte 값을 읽는 매크로<br />pgm_read_dword(address_short)&nbsp; &nbsp;//&nbsp;&nbsp;포인터 주소의 4 byte 값을 읽는 매크로<br />pgm_read_float(address_short)&nbsp; &nbsp; &nbsp; // &nbsp;포인터 주소의 float 값(4 byte)을 읽는 매크로<br />pgm_read_ptr(address_short)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 16비트 포인터 주소를 읽는 매크로, uint16_t</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">예) pgm_read_byte(value + 2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; (배열 이름(배열 주소)&nbsp;+ 배열 인덱스)&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">상기 매크로들은 PROGMEM 수식어가 정의된&nbsp;pgmspace.h 라이브러리에 정의된 매크로들이고 사용 예제에서는 상기 매크로들을 이용하여 PROGMEM 수식어로 정의된 배열에 접근하고 값을 읽게 된다. 이때 매크로에 사용되는 매개변수는 Flash memory에 저장된&nbsp;변수의&nbsp;주소 값이 들어가게 된다. 배열의 인덱스를 활용하여 값을 가져오기 위해서는 상기와 같이 주소 값에 인덱스 값을 더 해주면 된다. arry[배열 인덱스] 형식은 사용할 수 없다.&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아래 코드를 업로드하고 테스트해보자.</p>
<figure class="fileblock" style="margin: 28px auto 20px; max-width: 100%; clear: both; width: 470px; height: 71px; border: 1px solid rgb(233, 233, 233); position: relative; border-radius: 1px; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><a href="https://blog.kakaocdn.net/dn/czWG68/btqzOlcixGy/fabaHcQtiwfshWaiKvYrJ1/progmem_print_test.ino?attach=1&amp;knm=tfile.ino" style="color: #000000; text-decoration-line: none; transition: all 0.3s ease 0s; display: block; height: 71px;" target="_blank">
      <div class="image" style="box-sizing: border-box; position: absolute; left: 0px; top: 0px; width: 30px; height: 30px; background-image: url(&quot;https://t1.daumcdn.net/tistory_admin/static/manage/post-editor/img_editor_content.svg&quot;); background-position: 0px 0px; margin: 21px 17px 20px 22px;">&nbsp;</div>
      <div class="desc" style="box-sizing: border-box; position: absolute; left: 70px; right: 60px; top: 0px; bottom: 0px;">
         <div class="filename" style="box-sizing: border-box; color: #333333; font-size: 14px; text-overflow: ellipsis; height: 20px; margin: 17px 0px 0px;"><span class="name" style="box-sizing: border-box; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 272px; height: 20px; display: block;">progmem_print_test.ino</span></div>
         <div class="size" style="box-sizing: border-box; font-family: &quot;Avenir Next&quot;, sans-serif; font-size: 12px; color: #777777; height: 16px; margin: 2px 0px 0px;">0.00MB</div>
         </div>
      </a></figure>
<pre id="code_1573959987615" class="c++ cpp arduino" data-ke-language="c++" data-ke-type="codeblock" style="overflow: auto hidden; padding: 10px; margin-top: 5px; margin-bottom: 5px; max-width: 100%; border: 1px solid rgb(221, 221, 221); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 21.6px; font-family: &quot;Lucida Console&quot;; background-color: #fafafa; border-radius: 3px;">
   <code class="hljs cpp" style="border: 1px solid rgb(238, 238, 238); background: rgb(40, 44, 52); color: #abb2bf; border-radius: 5px; padding: 0.5em; margin: 3px 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 17px; line-height: 1.3em; font-family: D2Coding, monospace; display: block; overflow-x: auto;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">uint8_t</span> value1[] PROGMEM = { <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">28</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">255</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">10</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">117</span> };              <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 1 byte 자료형</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">int8_t</span> value2[] PROGMEM = { <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">36</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">-5</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">-26</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">99</span> };                  <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 1 byte 자료형</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">uint16_t</span> value3[] PROGMEM = { <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">65000</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">32796</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">16843</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">10</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">11234</span> };  <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 2 byte 자료형</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">float</span> value4[] PROGMEM = { <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">19.0</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">2.5</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">22.56</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">-8.9</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">3.5</span> };        <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// float 자료형(4 byte)</span><span class="hljs-function" style="box-sizing: border-box; color: #61aeee;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: border-box;">setup</span><span class="hljs-params" style="box-sizing: border-box; color: #a6e22e;">()</span></span>{ 
  Serial.begin(<span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">9600</span>);  
  Serial.println(pgm_read_byte(value1 + <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">2</span>)); <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 1 byte 자료형 읽기, value1 인덱스 2번 값 출력</span>
  Serial.println((<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">int8_t</span>)pgm_read_byte(value2 + <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">1</span>)); <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 1 byte 자료형 읽기, value2 값을 읽어와 signed로 변환</span>
  Serial.println(pgm_read_word(value3 + <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">1</span>)); <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// 2 byte 자료형 읽기</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">for</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">int</span> i = <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>; i &lt; <span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(value4)/<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(value4[<span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>]); i++) { <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// float는 4바이트 자료형</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">float</span> float_val = pgm_read_float(value4 + i); 
    Serial.print(float_val);
    Serial.print(<span class="hljs-string" style="box-sizing: border-box; color: #98c379;">","</span>);
  }
}
<span class="hljs-function" style="box-sizing: border-box; color: #61aeee;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: border-box;">loop</span><span class="hljs-params" style="box-sizing: border-box; color: #a6e22e;">()</span></span>{
}</code>
   </pre>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">시리얼 모니터 출력 값</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">255&nbsp;<br />-5&nbsp;<br />32796&nbsp;<br />19.00,2.50,22.56,-8.90,3.50,</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아두이노에서&nbsp;PROGMEM 지시어에 의해 저장된 배열을&nbsp;PROGMEM 지시어를 사용하지 않은 일반 배열로 취급하여 "Serial.println(value[0]);"처럼 코드를 작성할 경우 정상적으로 값을 읽어올 수도 있고 값을 읽지 못하거나 엉뚱한 값을 읽어 올 수도 있다.&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;</p>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">아래 코드를 아두이노에 업로드하고 시리얼 모니터를 확인해보면&nbsp;"Serial.println(value [i]);" 코드에 의한 출력 값이 정상적으로 표시되지 않는 것을 확인할 수 있다.</p>
<figure class="fileblock" style="margin: 28px auto 20px; max-width: 100%; clear: both; width: 470px; height: 71px; border: 1px solid rgb(233, 233, 233); position: relative; border-radius: 1px; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><a href="https://blog.kakaocdn.net/dn/4F2YG/btqzNBUd6le/iYyIzaKPNra8xzFEU3Pehk/progmem_array_test_error.ino?attach=1&amp;knm=tfile.ino" style="color: #000000; text-decoration-line: none; transition: all 0.3s ease 0s; display: block; height: 71px;" target="_blank">
      <div class="image" style="box-sizing: border-box; position: absolute; left: 0px; top: 0px; width: 30px; height: 30px; background-image: url(&quot;https://t1.daumcdn.net/tistory_admin/static/manage/post-editor/img_editor_content.svg&quot;); background-position: 0px 0px; margin: 21px 17px 20px 22px;">&nbsp;</div>
      <div class="desc" style="box-sizing: border-box; position: absolute; left: 70px; right: 60px; top: 0px; bottom: 0px;">
         <div class="filename" style="box-sizing: border-box; color: #333333; font-size: 14px; text-overflow: ellipsis; height: 20px; margin: 17px 0px 0px;"><span class="name" style="box-sizing: border-box; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 272px; height: 20px; display: block;">progmem_array_test_error.ino</span></div>
         <div class="size" style="box-sizing: border-box; font-family: &quot;Avenir Next&quot;, sans-serif; font-size: 12px; color: #777777; height: 16px; margin: 2px 0px 0px;">0.00MB</div>
         </div>
      </a></figure>
<pre id="code_1573959987617" class="c++ cpp arduino" data-ke-language="c++" data-ke-type="codeblock" style="overflow: auto hidden; padding: 10px; margin-top: 5px; margin-bottom: 5px; max-width: 100%; border: 1px solid rgb(221, 221, 221); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 21.6px; font-family: &quot;Lucida Console&quot;; background-color: #fafafa; border-radius: 3px;">
   <code class="hljs cpp" style="border: 1px solid rgb(238, 238, 238); background: rgb(40, 44, 52); color: #abb2bf; border-radius: 5px; padding: 0.5em; margin: 3px 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 17px; line-height: 1.3em; font-family: D2Coding, monospace; display: block; overflow-x: auto;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">float</span> value[] PROGMEM = { <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">19.0</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">2.5</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">22.56</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">-8.9</span>, <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">3.5</span> }; 
<span class="hljs-function" style="box-sizing: border-box; color: #61aeee;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: border-box;">setup</span><span class="hljs-params" style="box-sizing: border-box; color: #a6e22e;">()</span></span>{
  Serial.begin(<span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">9600</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">//  Serial.println(value[0]); // 에러 테스트용 주석처리</span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">for</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">int</span> i = <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>; i &lt; <span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(value)/<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(value[<span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>]); i++) { <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// float는 4바이트 자료형 </span><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">float</span> float_val = pgm_read_float(value + i);  
    Serial.println(float_val); <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// output the buffer.  </span>
  } 
  <span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">for</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">int</span> i = <span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>; i &lt; <span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(value)/<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">sizeof</span>(value[<span class="hljs-number" style="box-sizing: border-box; color: #d19a66;">0</span>]); i++) { <span class="hljs-comment" style="box-sizing: border-box; color: #b18eb1; font-style: italic;">// float는 4바이트 자료형 </span>
    Serial.println(value[i]); 
  }
}
<span class="hljs-function" style="box-sizing: border-box; color: #61aeee;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: border-box;">loop</span><span class="hljs-params" style="box-sizing: border-box; color: #a6e22e;">()</span></span>{
}</code>
   </pre>
<figure class="imageblock alignCenter" width="600" data-filename="progmem_arry_error.jpg" data-origin-width="0" data-origin-height="0" style="margin: 0px auto 20px; max-width: 100%; clear: both; display: table; position: relative; text-align: center; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><span data-url="https://blog.kakaocdn.net/dn/ble5or/btqzPvx2h5u/gJFjWuBsaE7LGCzgEGi7E0/img.jpg" data-lightbox="lightbox" data-alt="" style="box-sizing: border-box; cursor: pointer;"><img src="https://blog.kakaocdn.net/dn/ble5or/btqzPvx2h5u/gJFjWuBsaE7LGCzgEGi7E0/img.jpg" srcset="https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fble5or%2FbtqzPvx2h5u%2FgJFjWuBsaE7LGCzgEGi7E0%2Fimg.jpg" width="600" data-filename="progmem_arry_error.jpg" data-origin-width="0" data-origin-height="0" style="border: 0px; max-width: 100%; display: inline-block; margin: 0px; height: auto;" /></span></figure>
<p style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">다시 Serial.println(value[0]); 코드의 주석을 풀고 업로드해보면 정상적으로 값이 출력됨을 확인할 수 있다.&nbsp;</p>
<figure class="imageblock alignCenter" width="600" data-filename="progmem_arry_error1.jpg" data-origin-width="0" data-origin-height="0" style="margin: 0px auto 20px; max-width: 100%; clear: both; display: table; position: relative; text-align: center; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;"><span data-url="https://blog.kakaocdn.net/dn/bSBEV9/btqzOXu0UpX/uQjE12FOhzIdUOfJL5eFM0/img.jpg" data-lightbox="lightbox" data-alt="" style="box-sizing: border-box; cursor: pointer;"><img src="https://blog.kakaocdn.net/dn/bSBEV9/btqzOXu0UpX/uQjE12FOhzIdUOfJL5eFM0/img.jpg" srcset="https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbSBEV9%2FbtqzOXu0UpX%2FuQjE12FOhzIdUOfJL5eFM0%2Fimg.jpg" width="600" data-filename="progmem_arry_error1.jpg" data-origin-width="0" data-origin-height="0" style="border: 0px; max-width: 100%; display: inline-block; margin: 0px; height: auto;" /></span></figure>
<p><br style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;" /><br style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;" /><span style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">출처:&nbsp;</span><a href="https://postpop.tistory.com/92?category=744994" style="color: #000000; text-decoration-line: none; transition: all 0.3s ease 0s; font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;" target="_blank">https://postpop.tistory.com/92?category=744994</a><span style="font-family: &quot;Ubuntu Condensed&quot;, &quot;Noto Sans Korean&quot;; font-size: 16px; background-color: #f1f1f1;">&nbsp;[postpop]</span></p>