Per Mårtensson 4 years ago
commit
211901e462
33 changed files with 5090 additions and 0 deletions
  1. 21 0
      LICENSE
  2. 891 0
      README.html
  3. 686 0
      README.md
  4. BIN
      examples/AnalogRead To Progress Bar/AnalogRead To Progress Bar.HMI
  5. 139 0
      examples/AnalogRead To Progress Bar/AnalogReadToProgressbarCode/AnalogReadToProgressbarCode.ino
  6. BIN
      examples/AnalogRead To Waveform/AnalogRead To Waveform.HMI
  7. 131 0
      examples/AnalogRead To Waveform/AnalogReadToWaveformCode/AnalogReadToWaveformCode.ino
  8. BIN
      examples/ChangePagesAndSendFloatValues/ChangePagesAndSendFloatValues.HMI
  9. 294 0
      examples/ChangePagesAndSendFloatValues/ChangePagesAndSendFloatValuesCode/ChangePagesAndSendFloatValuesCode.ino
  10. BIN
      examples/ExampleReadCustomCommand/easyNexReadCustomCommand.HMI
  11. 198 0
      examples/ExampleReadCustomCommand/easyNexReadCustomCommand/easyNexReadCustomCommand.ino
  12. BIN
      examples/FourStepExample/FourStepExample.HMI
  13. 71 0
      examples/FourStepExample/FourStepExampleCode/FourStepExampleCode.ino
  14. 71 0
      examples/FourStepExample/FourStepExampleCodeWeMos/FourStepExampleCodeWeMos.ino
  15. BIN
      examples/ReadAndWriteNumber/ReadAndWriteNumber.HMI
  16. 73 0
      examples/ReadAndWriteNumber/ReadAndWriteNumberCode/ReadAndWriteNumberCode.ino
  17. 61 0
      examples/ReadString/ReadFromStringExample/ReadFromStringExample.ino
  18. BIN
      examples/ReadString/readStr.HMI
  19. BIN
      examples/Trigger/Trigger.HMI
  20. 101 0
      examples/Trigger/TriggerCode/TriggerCode.ino
  21. 100 0
      examples/Trigger/TriggerCodeWeMos/TriggerCodeWeMos.ino
  22. BIN
      examples/WriteTextAndCommands/WriteTextAndCommands.HMI
  23. 95 0
      examples/WriteTextAndCommands/WriteTextAndCommandsCode/WriteTextAndCommandsCode.ino
  24. 891 0
      extras/README.html
  25. BIN
      extras/media/AttributePane.png
  26. BIN
      extras/media/EasyNextionLibrary_Arduino_Library_Manager.png
  27. 87 0
      keywords.txt
  28. 9 0
      library.properties
  29. 337 0
      src/EasyNextionLibrary.cpp
  30. 157 0
      src/EasyNextionLibrary.h
  31. 291 0
      src/callTriggers.cpp
  32. 146 0
      src/readCustomCommands.cpp
  33. 240 0
      src/trigger.h

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 Athanasios Seitanis
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 891 - 0
README.html

@@ -0,0 +1,891 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>READMEV1</title>
+  <link rel="stylesheet" href="https://stackedit.io/style.css" />
+</head>
+
+<body class="stackedit">
+  <div class="stackedit__html"><h1 id="easy-nextion-library">Easy Nextion Library</h1>
+<h2 id="description">Description</h2>
+<p>A simple library that uses only four functions. You can easily benefit from Nextion’s wide range of features and advantages in just a few easy steps.<br>
+The library uses a custom protocol that can prove to be a <strong>powerful tool</strong> for advanced users as it can be <strong>easily modified</strong> to meet one’s needs.<br>
+This is an attempt to give a very simple method to use Nextion monitors for beginners at programming and at the same time to be a strong and reliable method that can be capable of satisfying the needs of the advance programming.<br>
+The handling of Nextion should be as simple and at the same time as professional as a display of this kind deserves.</p>
+<p>I have invested time and resources providing open source codes, like this one. Please do not hesitate to support my work!<br>
+If you found this work useful and has saved you time and effort,<br>
+just simply paypal me at this Link: <a href="https://paypal.me/seithan">seithagta@gmail.com</a></p>
+<p>You can find more examples, tutorials and projects with Nextion on my website <a href="https://seithan.com/">seithan.com</a> or at my YouTube channel <a href="https://www.youtube.com/channel/UCk_AjYtvzUC58ups5Lm053g">Thanasis Seitanis</a></p>
+<h2 id="installation">Installation</h2>
+<h3 id="first-method">First Method</h3>
+<ol>
+<li>In the Arduino IDE, navigate to Sketch &gt; Include Library &gt; Manage Libraries</li>
+<li>Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.</li>
+<li>Then search for EasyNextionLibrary using the search bar.</li>
+<li>Click on the text area and then select the latest version and install it.</li>
+</ol>
+<p><img src="./extras/media/EasyNextionLibrary_Arduino_Library_Manager.png" alt="enter image description here"></p>
+<h3 id="second-method">Second Method</h3>
+<ol>
+<li>Download the latest release of EasyNextionLibrary.</li>
+</ol>
+<ul>
+<li>From: <a href="https://github.com/Seithan/EasyNextionLibrary">https://github.com/Seithan/EasyNextionLibrary</a></li>
+</ul>
+<ol start="2">
+<li>Extract the <code>.zip</code> file</li>
+<li>Copy the EasyNextionLibrary folder, to: …\Arduino\libraries\</li>
+</ol>
+<p><em><strong>NOTE</strong></em>: <code>.HMI</code> files for Nextion Editor are also included in every example’s folder.<br>
+All <code>.HMIs</code> are set for 2.8" Basic screens, so as to be easier to modify it for bigger screens.</p>
+<h2 id="the-main-functions">The main functions</h2>
+<ul>
+<li><code>begin();</code></li>
+<li><code>writeNum();</code></li>
+<li><code>writeStr();</code></li>
+<li><code>readNumber();</code></li>
+<li><code>trigger();</code></li>
+<li><code>readStr();</code> Added with version 1.0.4</li>
+</ul>
+<p><em><strong>And the public variables:</strong></em></p>
+<ul>
+<li>currentPageId (Data Type: <strong>Integer</strong>)</li>
+<li>lastCurrentPageId (Data Type: <strong>Integer</strong>)</li>
+</ul>
+<p><strong>Functions for user custom command protocol</strong></p>
+<ul>
+<li><code>readByte();</code> Added with version 1.0.5</li>
+<li><code>easyNexReadCustomCommand()</code> Added with version 1.0.5<br>
+and the public variables for user custom command protocol Added with version 1.0.5</li>
+<li><code>cmdGroup</code> (Data Type: <strong>Byte</strong>)</li>
+<li><code>cmdLength</code> (Data Type: <strong>Byte</strong>)</li>
+</ul>
+<h3 id="details-examples-and-explanation-on-custom-protocol-can-be-found-on-my-website-at">Details, examples and explanation on custom protocol, can be found on my website at:</h3>
+<h4 id="httpsseithan.comeasy-nextion-librarycustom-protocol"><a href="https://seithan.com/Easy-Nextion-Library/Custom-Protocol/">https://seithan.com/Easy-Nextion-Library/Custom-Protocol/</a></h4>
+<h2 id="step-example">4-step Example</h2>
+<ol>
+<li><strong>Include</strong> <em><strong>EasyNextionLibrary</strong></em> and create an object of <code>EasyNex</code> class</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"EasyNextionLibrary.h"</span>  </span><span class="token comment">// Include EasyNextionLibrary</span>
+
+EasyNex <span class="token function">myNex</span><span class="token punctuation">(</span>Serial<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Create an object of EasyNex class with the name &lt; myNex &gt; </span>
+                       <span class="token comment">// Set as parameter the Hardware Serial you are going to use</span>
+</code></pre>
+<ol start="2">
+<li><strong>Begin the object</strong> and give the desired baud rate as a parameter. Also, initialize the built-in LED as output</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">9600</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Begin the object with a baud rate of 9600</span>
+                     <span class="token comment">// If no parameter was given in the begin(), the default baud rate of 9600 will be used </span>
+  <span class="token function">pinMode</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> OUTPUT<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// The built-in LED is initialized as an output                     </span>
+<span class="token punctuation">}</span>
+</code></pre>
+<ol start="3">
+<li><strong>Place</strong> the <strong>NextionListen()</strong> function in the loop.</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">NextionListen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// This function must be called repeatedly to response touch events</span>
+                         <span class="token comment">// from Nextion touch panel. Actually, you should place it in your loop function.</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<ol start="4">
+<li><strong>Select one of the 50 predefined trigger()</strong> functions and use it as a simple void function (nothing returned).<br>
+Declare the void function by simply writing:</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+<span class="token punctuation">[</span> put your code here <span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">]</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<ul>
+<li>Write the code you want to run in there.<br>
+The <code>trigger0()</code> function will run every time the following sequence of bytes (in HEX format) <code>23 02 54 00</code> comes to Arduino’s Serial. To do that, write in the <code>Touch Release Event</code> of the button b0, this command: <code>printh 23 02 54 00</code></li>
+</ul>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+
+  <span class="token function">digitalWrite</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> <span class="token operator">!</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
+  <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> HIGH<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">2016</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to GREEN (color code: 2016)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"ON"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+    
+  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> LOW<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">63488</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to RED (color code: 63488)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"OFF"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+  <span class="token punctuation">}</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p>Enjoy the Easy Nextion Library!! Please do not forget the LED on :)</p>
+<h2 id="full-example-code">Full Example Code</h2>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token comment">/*
+ * FourStepExample.ino - Simple example code
+ * Copyright (c) 2020 Athanasios Seitanis &lt; seithagta@gmail.com &gt;. 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */</span>
+<span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"EasyNextionLibrary.h"</span>  </span><span class="token comment">// Include EasyNextionLibrary</span>
+
+EasyNex <span class="token function">myNex</span><span class="token punctuation">(</span>Serial<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Create an object of EasyNex class with the name &lt; myNex &gt; </span>
+                       <span class="token comment">// Set as parameter the Hardware Serial you are going to use</span>
+
+<span class="token keyword">void</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">9600</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Begin the object with a baud rate of 9600</span>
+                     <span class="token comment">// If no parameter was given in the begin(), the default baud rate of 9600 will be used </span>
+                     
+  <span class="token function">pinMode</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> OUTPUT<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// The built-in LED is initialized as an output                     </span>
+<span class="token punctuation">}</span>
+
+<span class="token keyword">void</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">NextionListen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// This function must be called repeatedly to response touch events</span>
+                         <span class="token comment">// from Nextion touch panel. Actually, you should place it in your loop function.</span>
+<span class="token punctuation">}</span>
+
+<span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  <span class="token comment">/* Create a button on Nextion
+   * Write in the Touch Release Event of the button
+   * this command:    printh 23 02 54 00
+   * Every time the button is pressed, the trigger0() function will run
+   * and the code inside will be executed once
+   */</span>
+  <span class="token function">digitalWrite</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> <span class="token operator">!</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//If LED_BUILTIN is ON, turn it OFF, or the opposite</span>
+  <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> HIGH<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">2016</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to GREEN (color code: 2016)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"ON"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+    
+  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> LOW<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">63488</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to RED (color code: 63488)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"OFF"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+  <span class="token punctuation">}</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<h2 id="function-documentation">Function documentation</h2>
+<p><em><strong>The various combinations of attribute choices provide a wide range of expected behaviors with many combinations.<br>
+This combined with the Nextion Instruction Set creates the opportunity for very powerful HMIs.</strong></em></p>
+<p><em><strong>NOTE</strong></em>:<br>
+As these commands are using the Serial port to read and write, it is more preferred not to run them in the loop() without delay(); or some other method of not running them with the frequency of the loop and use them only when it is needed.<br>
+Using them in a loop, a delay in the loop can be noticed, especially when reading from the Serial. A Serial buffer overflow can also be caused.<br>
+<em><strong>Also NOTE</strong></em>: (from the Nextion Editor Guide)</p>
+<blockquote>
+<p>In an HMI project a page is a localized unit. When changing pages, the existing page is removed from memory and the &gt; &gt; requested page is then loaded into memory. As such components with a variable scope of <em><strong>local</strong></em> are only accessible while the page they are in is currently loaded. Components within a page that have a variable scope of <em><strong>global</strong></em> are accessible by prefixing the page name to the global component .objname.<br>
+As an Example:<br>
+A global Number component n0 on page1 is accessed by <strong>page1.n0</strong> .<br>
+A local Number component n0 on page1 can be accessed by page1.n0 or n0, but there is little sense to try access a local component if the page is not loaded. Only the component attributes of a global component are kept in memory. Event code is never global in nature.</p>
+</blockquote>
+<h3 id="function-trigger">Function trigger();</h3>
+<p><strong><code>Associated Library's Code Example:</code></strong> <strong><em><code>Trigger</code></em> <strong><code>and</code></strong> <em><code>FourStepExample</code></em></strong></p>
+<p><em><strong>Description:</strong></em><br>
+This is the most important function of the library.<br>
+And this is because, it gives you the ability to use the predefined functions and run your code from there.<br>
+These predefined functions are named <code>trigger0()</code>, <code>trigger1()</code>, <code>trigger2()</code>… up to <code>trigger50()</code>.<br>
+You can use them as a simple void function out of the loop, in which you will have written a block of code to run every time it is called.<br>
+You can call those <code>trigger()</code> functions and run the code they contain anytime by simply writing in a Nextion Event the command: <code>printh 23 02 54 XX</code> , where <code>XX</code> the id for the triggerXX() in HEX.<br>
+For example in a button’s Touch Release Event, write:</p>
+
+<table>
+<thead>
+<tr>
+<th>Command</th>
+<th>Function</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>printh 23 02 54 00</td>
+<td>trigger0()</td>
+</tr>
+<tr>
+<td>printh 23 02 54 01</td>
+<td>trigger1()</td>
+</tr>
+<tr>
+<td>…</td>
+<td>…</td>
+</tr>
+<tr>
+<td>printh 23 02 54 0A</td>
+<td>trigger10()</td>
+</tr>
+<tr>
+<td>… up to</td>
+<td>… up to</td>
+</tr>
+<tr>
+<td>printh 23 02 54 32</td>
+<td>trigger50()</td>
+</tr>
+</tbody>
+</table><p>In Arduino code, declare a void <code>trigger()</code> function with the predefined name you want to use and put your code there.<br>
+Declare the void function by simply writing:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+<span class="token punctuation">[</span> put your code here <span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">]</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p>Example:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"EasyNextionLibrary.h"</span></span>
+
+EasyNex <span class="token function">myObject</span><span class="token punctuation">(</span>Serial<span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token keyword">void</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">9600</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+  <span class="token function">pinMode</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> OUTPUT<span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+<span class="token keyword">void</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">NextionListen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+<span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  <span class="token function">digitalWrite</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> <span class="token operator">!</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>1st NOTE</strong></em>: To change the predefined names of the <code>trigger()</code> functions, there are details inside the <code>trigger.cpp</code> file and you can add up to <strong>255</strong> functions of this kind.<br>
+<em><strong>2nd NOTE</strong></em>: You can send  the same <code>printh</code> command, to call the same function, from more than one component from any page, depending on your needs</p>
+<p><em>See Appendix at the end of the document for numbers in HEX table</em></p>
+<h3 id="function-begin">Function begin();</h3>
+<p><em><strong>Parameters:</strong></em><br>
+begin(<code>unsigned long</code>)<br>
+<strong>unsigned long</strong>: unsigned long baud = <strong>9600</strong> (default) if nothing is written in the begin() function</p>
+<p><em><strong>Description:</strong></em><br>
+<strong>The begin()</strong> method of the class in which we pass the initialization data to the objects.</p>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">115200</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// for baud rate 115200</span>
+</code></pre>
+<h3 id="function-writenum">Function writeNum();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ReadAndWriteNumber</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em><br>
+writeNum(<code>String</code>, <code>uint32_t</code>)</p>
+<ul>
+<li><strong>String</strong> = objectname.numericAttribute (example: “n0.val”  or “n0.bco”…etc)</li>
+<li><strong>uint32_t</strong> = value (example: 84)(number from 0 to 4,294,967,295)</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+For writing numbers in numeric attributes in components of any kind (variables, textboxes,  etc.).</p>
+<ul>
+<li>We can change the shown value of a number box</li>
+<li>We can change the value of a numeric attribute of the design editing commands. Those commands are used to change the attribute of the components (button, text box, timer, numeric etc.) while Nextion is running.</li>
+</ul>
+
+<table>
+<thead>
+<tr>
+<th>Command</th>
+<th>Result on n0 comp.</th>
+<th>Syntax</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>n0.val=30</td>
+<td>Sets n0 component’s shown value to 30</td>
+<td><code>myObject.writeNum("n0.val", 30);</code></td>
+</tr>
+<tr>
+<td>va0.val=30</td>
+<td>Sets va0 variable’s value to 30</td>
+<td><code>myObject.writeNum("va0.val", 30);</code></td>
+</tr>
+<tr>
+<td>n0.bco=63488</td>
+<td>Sets background color to red</td>
+<td><code>myObject.writeNum("n0.bco", 63488);</code></td>
+</tr>
+<tr>
+<td>n0.font=0</td>
+<td>Sets font to font style with Id = 0</td>
+<td><code>myObject.writeNum("n0.font", 0);</code></td>
+</tr>
+<tr>
+<td>n0.pco=1055</td>
+<td>Sets font color to blue</td>
+<td><code>myObject.writeNum("n0.pco", 1055);</code></td>
+</tr>
+<tr>
+<td>n0.format=0</td>
+<td>Sets value format to decimal</td>
+<td><code>myObject.writeNum("n0.format", 0);</code></td>
+</tr>
+</tbody>
+</table><p>With the same way you can change the xcen, ycen, length and isbr</p>
+<p><em><strong>TIP:</strong> In a timer component, at the attribute &lt; <strong>en</strong> &gt;, you can start or stop the timer by writing <strong>0</strong> or <strong>1</strong>.</em><br>
+Also, at the attribute &lt; <strong>tim</strong> &gt;, you can set the time the timer is going to repeat the commands written in timer’s User-code event.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"tm0.en"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">// 0 = stop, 1 = start</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"tm0.tim"</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// repeat code every 1000ms</span>
+</code></pre>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.val"</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// Set the value of numeric n0 to 30</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.bco"</span><span class="token punctuation">,</span> <span class="token number">63488</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set background color of n0 to 63488(red)</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.font"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// Set font to font style with ID 0</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.pco"</span><span class="token punctuation">,</span> <span class="token number">1055</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Set font color to blue</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.format"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Set value format to decimal</span>
+</code></pre>
+<p><em><strong>NOTE:</strong> Only attributes shown in green in the Editor can be both read and changed by user code at runtime.</em><br>
+<img src="./extras/media/AttributePane.png" alt="Attribute panel"></p>
+<h3 id="send-floating-point-numbers-a-number-that-has-a-decimal-point.">Send floating-point numbers, a number that has a decimal point.</h3>
+<h3 id="or-send-a-number-on-a-textbox">Or send a number on a textbox</h3>
+<p><em><strong>Description:</strong></em><br>
+Nextion <strong>DOES NOT SUPPORT</strong> float numbers. Instead, it uses integer math and does not have real or floating support.<br>
+The Xfloat component is used for signed 32-bit integer values.<br>
+The <code>.vvs0</code> sets the number of digits shown to the left of the decimal (useful for leading zeros).<br>
+The <code>.vvs1</code> sets the number of digits shown to the right of the decimal.</p>
+<p><em><strong>You can send Floating-point numbers with these two ways</strong></em>:</p>
+<ul>
+<li>On a <strong>Xfloat component</strong> after you convert the float to int and multiply it by 10, the Xfloat component will put a comma <code>,</code> (decimal point) automatically after the last digit  if attribute <code>vvs1</code> is set to 1.</li>
+</ul>
+<p><em><strong>Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">int</span> tempInt <span class="token operator">=</span> temperature<span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">;</span>      <span class="token comment">// Convert the float to int. Multiply it x10                       </span>
+myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"x0.val"</span><span class="token punctuation">,</span> tempInt<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Write it to x0 Xfloat component on Nextion</span>
+</code></pre>
+<p>it is obvious that if you want 2 decimal places, you will set the attribute <code>vvs1</code> to <code>2</code> and you will multiply by <code>100</code></p>
+<ul>
+<li>On a <strong>Textbox component</strong> after you convert the float value to String</li>
+</ul>
+<p><em><strong>Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">String tempString <span class="token operator">=</span> <span class="token function">String</span><span class="token punctuation">(</span>temperature<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Convert the float value to String, with 1 decimal place</span>
+myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> tempString<span class="token punctuation">)</span><span class="token punctuation">;</span>       <span class="token comment">// Write the String value to t0 Textbox component</span>
+</code></pre>
+<h3 id="function-writestr">Function writeStr();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>WriteTextAndCommands</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em></p>
+<ul>
+<li>
+<p>writeStr(<code>String</code>, <code>String</code>). <em>To change the <code>.txt</code> attribute in components</em><br>
+<strong>String No1</strong>: objectname.textAttribute (example: “t0.txt”  or “b0.txt”)<br>
+<strong>String No2</strong>: value (example: “Hello World”)</p>
+</li>
+<li>
+<p>writeStr(<code>String</code>). <em>To send Designing and System Commands</em><br>
+<strong>String</strong>: The command to send on Nextion</p>
+</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+For writing text in Nextion. The two ways the command can be used:</p>
+<p><strong>First Usage of the command</strong>:<br>
+Use <strong>writeStr(</strong> <code>String</code>, <code>String</code> <strong>)</strong> to change the text in a textbox<br>
+Use both parameters to write text in textboxes.</p>
+<ul>
+<li>In the first parameter, write the objectName.textAttribute example: t0.txt or b0.txt</li>
+<li>In the second parameter, write the text you want to “print”</li>
+</ul>
+<p><em><strong>1st Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"Hello World"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Change t0 text to "Hello World"</span>
+</code></pre>
+<p>Any previous text on the textbox is deleted</p>
+<p>Avoid using very big text Strings in the same command, as Nextion will not recognise them. Istead use a second command and in order to add to the existing text, use the <strong><code>+</code></strong> symbol, after the <code>.textAttribute("t0.txt+")</code>.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"You are now transferred to page2\\rThank you\\rfor choosing my library!!!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt+"</span><span class="token punctuation">,</span> <span class="token string">"\\rEnjoy the library!!!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt+"</span><span class="token punctuation">,</span> <span class="token string">"\\r\\rAthanasios Seitanis\\rseithagta@gmail.com"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+  <span class="token comment">/* By writing \\r, you send Nextion the change line character &lt; \r &gt;
+   * The second \ is required, in order to print the \ as character
+   * and not as an escape character.
+   */</span>
+</code></pre>
+<p><strong>Second Usage of the command</strong>:<br>
+Use <strong>writeStr(</strong> <code>String</code> <strong>)</strong> to send Designing and System Commands according to the instructions of Nextion’s Instruction Set.<br>
+Use only the first parameter to send a command to Nextion. The commands must be syntaxed according to Nextion’s Instruction Set.</p>
+<p><em><strong>2nd Syntax:</strong></em><br>
+<em><strong>Design Commands Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"page page0"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Sending this command to change the page we are on Nextion using pageName</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"page 1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Sending this command to change the page we are on Nextion using pageId</span>
+</code></pre>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"cir 100,100,30,RED"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Renders a hollow Red circle with circle center at (100,100)</span>
+</code></pre>
+<p><em><strong>System Commands Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"dim=50"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set the current brightness level to 50%</span>
+</code></pre>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"sleep=1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// sleep=1 (Enter sleep mode) or sleep=0 (Exit sleep mode)</span>
+</code></pre>
+<p><em><strong>NOTE</strong>: When you decide to exit the sleep mode on Nextion, use a small delay of 50ms, in order to give Nextion some time to Exit sleep mode.</em><br>
+<em><strong>WARNING</strong>: DO NOT send commands that causes data return over Serial to MCU, unless you know what you are doing.</em><br>
+Commands that cause data return over serial:<br>
+<code>print</code>, <code>prints</code>, <code>printh</code>, <code>sendme</code>, <code>get</code>, <code>rept</code>, <code>rdfile</code>, <code>twfile</code><br>
+<em><strong>TIP</strong>: Write in the debug mode the command to check if it is written correctly</em></p>
+<h3 id="function-readnumber">Function readNumber();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ReadAndWriteNumber</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em><br>
+readNumber(<code>String</code>)</p>
+<ul>
+<li><strong>String</strong>: objectname.numericAttribute (example: “va0.val” “n0.val”, “n0.pco”, “n0.bco”…etc)</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+We use it to read the value of every components’ numeric attribute from Nextion (value, bco color, pco color…etc)</p>
+<p>In case the function fails to read the new value, it will return the number <code>777777</code>.<br>
+The reasons of getting <code>777777</code>: (from release 1.0.2 and above)</p>
+<ul>
+<li>Waiting bytes have not come to Serial timeout</li>
+<li>Command start character is not found in Serial timeout</li>
+<li>The waiting length of the byte package has not come to Serial</li>
+<li>Bytes on Serial are not the expected<br>
+The chances of getting a wrong value is one in a million.<br>
+You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value.<br>
+You can check it with an <strong><code>if()</code></strong> statement, in which you will ignore the value of <code>777777</code> and you can run the <code>readNumber()</code> again or set a safe value or use the last good known value method.</li>
+</ul>
+<pre class=" language-cpp"><code class="prism  language-cpp">uint32_t number <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
+uint32_t lastnumber <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
+
+number <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"n0.val"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// We read the value of n0 and store it to number variable</span>
+    
+<span class="token keyword">if</span><span class="token punctuation">(</span>number <span class="token operator">!=</span> <span class="token number">777777</span><span class="token punctuation">)</span><span class="token punctuation">{</span>       <span class="token comment">// 777777is the return value if the code fails to read the new value</span>
+  lastnumber <span class="token operator">=</span> number<span class="token punctuation">;</span>
+  
+<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>number <span class="token operator">==</span> <span class="token number">777777</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    number <span class="token operator">=</span> lastNumber<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">unsigned</span> <span class="token keyword">long</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"n0.val"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the value of numeric box n0</span>
+<span class="token keyword">unsigned</span> <span class="token keyword">long</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"va0.val"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the value of the variable va0</span>
+<span class="token keyword">unsigned</span> <span class="token keyword">int</span> y <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Strore to y the color number of the background of button b0</span>
+</code></pre>
+<p><em><strong>NOTE:</strong> Only attributes shown in <strong>green</strong> in the Editor can be both read and changed by user code at runtime.</em><br>
+To</p>
+<h3 id="function-readstr">Function readStr();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ReadString</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em><br>
+readStr(<code>String</code>)</p>
+<ul>
+<li><strong>String</strong>: objectname.textAttribute (example: “t0.txt”, “va0.txt”, “b0.txt”…etc)</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+We use it to read the value of every components’ text attribute from Nextion (txt etc…)</p>
+<p>In case the function fails to read the new value, it will return the text <code>ERROR</code>.<br>
+The reasons of getting <code>ERROR</code>: (from release 1.0.4 and above)</p>
+<ul>
+<li>Serial buffer occupied timeout</li>
+<li>Waiting bytes have not come to Serial timeout</li>
+<li>Command start character is not found in Serial timeout</li>
+<li>The end of the command has not come to Serial</li>
+</ul>
+<p>The chances of getting a wrong value is one in a million.<br>
+You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value.<br>
+You can check it with an <strong><code>if()</code></strong> statement, in which you will ignore the value of <code>ERROR</code> and you can run the <code>readStr()</code> again or set a safe value or use the last good known value method.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp">String text <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>
+String lastText <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>
+
+text <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// We read the value of t0 and store it</span>
+    
+<span class="token keyword">if</span><span class="token punctuation">(</span>text<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"ERROR"</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">{</span>       <span class="token comment">// ERROR is the return value if the code fails to read the new value</span>
+  lastText <span class="token operator">=</span> text<span class="token punctuation">;</span>
+  
+<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>text<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"ERROR"</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    text <span class="token operator">=</span> lastText<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">String x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the value of text box t0</span>
+</code></pre>
+<h2 id="library-public-variables">Library Public Variables</h2>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ChangePagesAndSentFloatValues</code></em></strong></p>
+<p><em><strong>1st Variable</strong></em>:<br>
+<em>currentPageId</em><br>
+A variable that stores the ID number of the current page loaded on Nextion. It is <strong>VERY</strong> important that Nextion and Arduino are synced and when you send data, the data goes to the right page.</p>
+<p><strong>NOTE</strong>: In order to update this variable with the current Id of the page, you must write the Preinitialize Event of every page: <code>printh 23 02 50 XX</code> , where <code>XX</code> the id of the page in HEX.<br>
+For page0: <code>printh 23 02 50 00</code><br>
+for page9: <code>printh23 02 50 09</code><br>
+for page10: <code>printh 23 02 50 0A</code></p>
+<p><em>See Appendix at the end of the document for numbers in HEX table</em></p>
+<p>It can be called by writing:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">int</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span>currentPageId<span class="token punctuation">;</span> <span class="token comment">// Store to x the currentPageId</span>
+</code></pre>
+<p><strong>Example</strong>:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"You are on page0!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"You are on page1!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>2nd Variable</strong></em>:<br>
+<em>lastCurrentPageId</em><br>
+This variable stores the last value of <code>currentPageId</code> before <code>currentPageId</code> is changed. We use it to check if the page we are on has changed, in order to send refreshing screen data to the components of the page.</p>
+<p>After that, it can be set to equal with the <code>currentPageId</code>, in order not to send unnecessary data for refreshing the components.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">!=</span> myObject<span class="token punctuation">.</span>lastCurrentPageId<span class="token punctuation">)</span><span class="token punctuation">{</span>
+  <span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    <span class="token punctuation">[</span>send the data to refresh the page0<span class="token punctuation">]</span>
+  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    <span class="token punctuation">[</span>send the data to refresh the page1<span class="token punctuation">]</span>
+  <span class="token punctuation">}</span>
+  myObject<span class="token punctuation">.</span>lastCurrentPageId <span class="token operator">=</span> myObject<span class="token punctuation">.</span>currentPageId<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p>Find more on the Library’s Example:  <em><code>ChangePagesAndSentFloatValues</code></em><br>
+<em><strong>TIP</strong>: You can read the ID of the current Loaded page at anytime, without the use of the Library’s commands using the <code>dp</code> system command</em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">int</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"dp"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the ID of the current Loaded page</span>
+</code></pre>
+<h3 id="function-easynexreadcustomcommand">Function easyNexReadCustomCommand()</h3>
+<p><code>easyNexReadCustomCommand()</code> has a weak attribute and will be created only when user<br>
+declares this function in the main code.<br>
+More for custom protocol and commands <a href="https://seithan.com/Easy-Nextion-Library/Custom-Protocol/">https://seithan.com/Easy-Nextion-Library/Custom-Protocol/</a><br>
+Our commands will have this format: <code>#</code>  <code>len</code>   <code>cmd</code>   <code>id</code>   <code>id2</code><br>
+and we must send them from Nextion as HEX with the printh command.<br>
+For example: <code>printh 23 03 4C 01 01</code></p>
+<ul>
+<li><code>#</code> start marker, declares that a command follows</li>
+<li><code>len</code> declares the number of bytes that will be received</li>
+<li><code>cmd</code> declares the task of the command or command group</li>
+<li><code>id</code> declares the properties of the command</li>
+<li><code>id2</code> a second property for the command</li>
+</ul>
+<p>When we send a custom command with the above format, the function NextionListen() will capture the start marker <code>#</code> and the <code>len</code> (first 2 bytes) and it will wait until all the bytes of the command, as we have declared with the <code>len</code> byte, arrive to the Serial buffer and inside the timeout limits.<br>
+After that, the function will read the next byte, which is the command group and the function <code>readCommand()</code> takes over and through a switch command tries to match the <code>_cmd</code> variable that holds the command group value with the statements of the cases.<br>
+If we do NOT have a match with the predefined, <code>cmd</code> of <code>P</code> for page and <code>T</code> for triggers, it will continue to the default where we store the <code>_cmd</code> and <code>_len</code> to the public variables <code>cmdGroup</code> and <code>cmdLenght</code> as we are going to need access to them from the main code in the next step.<br>
+Next we call the the <code>easyNexReadCustomCommand()</code>  with the precondition and ONLY if we have declared the function in the main code.<br>
+From this point we can handle the assign of <code>cmdGroup</code> and <code>IDs</code> from the <code>easyNexReadCustomCommand()</code> in the user code, where we can go on with a switch case<br>
+for the <code>cmdGroup</code>, the one that we have stored the <code>_cmd</code> for public use and we can call it with <code>myObject.cmdGroup</code>. This is why we made <code>cmdGroup</code> a public variable.</p>
+<p>As an example, we use 2 arrays (tables) of integers, where we are going to change the value of the position (element) with custom commands.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"> <span class="token keyword">int</span> dataL<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">//values 0 or 255, because we use only one byte</span>
+ <span class="token keyword">int</span> dataS<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">// values from 0 to 255, because we use only one byte</span>
+</code></pre>
+<p>The format is the known: <code>#</code>  <code>len</code>   <code>cmd</code>   <code>id</code>   <code>id2</code></p>
+<ul>
+<li>where the <code>id</code> referred to the position (element) of the array we want to write on</li>
+<li>And <code>id2</code> carries the value to be written on the element of array.</li>
+</ul>
+<p>The custom command from Nextion: <code>printh 23 03 4C 00 0A</code></p>
+<ul>
+<li>4C is the Hex for letter L and we refer to the array <code>dataL[]</code></li>
+<li>00 Hex of Dec number 0 used as the index for each array element</li>
+<li>0A Hex of Dec number 10 is the value we are going to write on element 0</li>
+</ul>
+<p>After the command is executed by our code, the values on <code>dataL[]</code> array will be</p>
+<ul>
+<li>dataL[4] = {10,0,0,0}</li>
+</ul>
+<p>Same for the dataS[] intead that cmd is the 53 in Hex for letter <code>S</code></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">easyNexReadCustomCommand</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+
+  <span class="token keyword">int</span> arrayPlace<span class="token punctuation">;</span> <span class="token comment">// temp variable</span>
+  <span class="token keyword">int</span> value<span class="token punctuation">;</span>      <span class="token comment">// temp variable</span>
+  
+  <span class="token keyword">switch</span><span class="token punctuation">(</span>myNex<span class="token punctuation">.</span>cmdGroup<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    
+    <span class="token keyword">case</span> <span class="token string">'L'</span><span class="token operator">:</span> <span class="token comment">// Or &lt;case 0x4C:&gt;  If 'L' matches</span>
+    <span class="token comment">// we are going to write values in specific places in the dataL[] table</span>
+    <span class="token comment">// read the next byte that determines the position on the table</span>
+    arrayPlace <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// read the next byte that keeps the value for the position</span>
+    value <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// update the array with the new values</span>
+    dataL<span class="token punctuation">[</span>arrayPlace<span class="token punctuation">]</span> <span class="token operator">=</span> value<span class="token punctuation">;</span>  
+    
+    <span class="token keyword">break</span><span class="token punctuation">;</span> 
+
+    <span class="token keyword">case</span> <span class="token string">'S'</span><span class="token operator">:</span> <span class="token comment">// Or &lt;case 0x53:&gt;  If 'S' matches </span>
+    
+    <span class="token comment">// we are going to write values in specific places in the dataS[] table</span>
+    <span class="token comment">// from Nextion printh 23 03 53 00 00</span>
+    <span class="token comment">// read the next byte that determines the position on the table</span>
+    arrayPlace <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// read the next byte that keeps the value for the position</span>
+    value <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// update the array with the new values</span>
+    dataS<span class="token punctuation">[</span>arrayPlace<span class="token punctuation">]</span> <span class="token operator">=</span> value<span class="token punctuation">;</span>  
+    
+    <span class="token keyword">break</span><span class="token punctuation">;</span>
+  <span class="token punctuation">}</span>  
+<span class="token punctuation">}</span>
+</code></pre>
+<h2 id="usefull-tips">Usefull Tips</h2>
+<p><strong>Manage Variables</strong><br>
+You can read/write the variables as any other component.</p>
+<p>Use <code>readNumber()</code> to read the value of a numeric variable.<br>
+Example: <code>myNex.readNumber("va0.val");</code><br>
+<strong>BUT:</strong>  <code>myNex.readNumber("sys0");</code></p>
+<p>Use <code>writeNum()</code> to change the value of a numeric variable.<br>
+Example: <code>myNex.writeNum("va0.val", 255);</code><br>
+<strong>BUT:</strong>  <code>myNex.readNumber("sys0", 375);</code></p>
+<p>Use <code>readStr()</code> to read the text of a String variable.<br>
+Example: <code>myNex.readStr("va0.txt");</code></p>
+<p>Use <code>writeStr()</code> to change the text of a String variable.<br>
+Example: <code>myNex.writeStr("va0.txt", "Hello World");</code><br>
+For this to happen, the variables you want to read/write must be at the page you are currently on.<br>
+Otherwise, if the variables are of <strong>global</strong> scope, you will need to use a prefix with the page name that the variables are at.<br>
+Example:<br>
+<code>myNex.readNumber("page0.va0.val");</code> // If the variable is at page0<br>
+The same goes for the other functions as well.</p>
+<h2 id="compatibility">Compatibility</h2>
+<ul>
+<li>Arduino</li>
+<li>ESP</li>
+</ul>
+<p>Tested MCUs:</p>
+<ol>
+<li>Arduino NANO</li>
+<li>Arduino MEGA 2560</li>
+<li>Arduino UNO</li>
+<li>WeMos D1 mini ESP8266</li>
+</ol>
+<h2 id="releases">Releases:</h2>
+<h3 id="release-1.0.5">Release 1.0.5</h3>
+<ul>
+<li>Updated <code>readNumber()</code> function for faster response and more accurate reading.</li>
+<li>Added the <code>readByte()</code> function for reading  Serial buffer from user code</li>
+<li>Added <code>easyNexReadCustomCommand()</code> function with a weak attribute and will be created only when user declares this function in the main code. The motivation to move this function out of the library’s files, comes from Ricardo Reis thanks to his issue <a href="https://github.com/Seithan/EasyNextionLibrary/issues/15">https://github.com/Seithan/EasyNextionLibrary/issues/15</a></li>
+<li>Added public variables <code>cmdGroup</code> and <code>cmdLength</code> <strong>ONLY</strong> for read custom commands, stores the command group ID and the length of the command</li>
+</ul>
+<h3 id="release-1.0.4">Release 1.0.4</h3>
+<ul>
+<li>Added the readStr() function for reading a String from Nextion</li>
+</ul>
+<h3 id="release-1.0.3">Release 1.0.3</h3>
+<p>Two more examples were added.</p>
+<ul>
+<li>The first one demonstrates how to use EasyNextionLibrary with waveforms.</li>
+<li>The  second one demonstrates how to use EasyNextionLibrary with progress bars</li>
+</ul>
+<h3 id="release-1.0.2">Release 1.0.2</h3>
+<ul>
+<li>Remove the private function <code>readCommand()</code> from the main <code>EasyNextionLibrary.cpp</code> file. A new file is created named <code>readCustomCommands.cpp</code>,  in order to make easier the modifications for it when using the custom protocol.</li>
+<li>Return Error code added and to other cases of <code>readNumberFromSerial()</code>. When failing to read a number, we  return the number 777777 instead. The cases of having a 777777 return:
+<ul>
+<li>Waiting bytes have not come to Serial timeout</li>
+<li>Command start character is not found in Serial timeout</li>
+<li>The waiting length of the byte package has not come to Serial</li>
+<li>Bytes on Serial are not the expected</li>
+</ul>
+</li>
+<li>The function readNumberFromSerial() is improved, making reading values more accurate, due to hardware or Serial problems.</li>
+</ul>
+<h2 id="licence">Licence</h2>
+<p>This library is licensed under <strong>MIT X11 license</strong>.<br>
+Copyright © &lt;2020&gt;  Athanasios Seitanis</p>
+<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
+<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
+<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
+<p>Except as contained in this notice, the name of Athanasios Seitanis or the name of EasyNextionLibrary shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Athanasios Seitanis.<br>
+Also, prior written permission is required if this software or any part of it or any modifications of it, are used for commercial purposes.</p>
+<p>By using this software, you agree with the above terms and conditions as they are.<br>
+The owner of the software has the right to change the terms of this license at any time without a prior notification.</p>
+<h2 id="appendix">Appendix</h2>
+<h3 id="numbers-in-hex">Numbers in HEX:</h3>
+
+<table>
+<thead>
+<tr>
+<th>DEC</th>
+<th>HEX</th>
+<th>-</th>
+<th>DEC</th>
+<th>HEX</th>
+<th>-</th>
+<th>DEC</th>
+<th>HEX</th>
+<th>-</th>
+<th>DEC</th>
+<th>HEX</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>0</td>
+<td><strong>00</strong></td>
+<td>-</td>
+<td>16</td>
+<td><strong>10</strong></td>
+<td>-</td>
+<td>32</td>
+<td><strong>20</strong></td>
+<td>-</td>
+<td>48</td>
+<td><strong>30</strong></td>
+</tr>
+<tr>
+<td>1</td>
+<td><strong>01</strong></td>
+<td>-</td>
+<td>17</td>
+<td><strong>11</strong></td>
+<td>-</td>
+<td>33</td>
+<td><strong>21</strong></td>
+<td>-</td>
+<td>49</td>
+<td><strong>31</strong></td>
+</tr>
+<tr>
+<td>2</td>
+<td><strong>02</strong></td>
+<td>-</td>
+<td>18</td>
+<td><strong>12</strong></td>
+<td>-</td>
+<td>34</td>
+<td><strong>22</strong></td>
+<td>-</td>
+<td>50</td>
+<td><strong>32</strong></td>
+</tr>
+<tr>
+<td>3</td>
+<td><strong>03</strong></td>
+<td>-</td>
+<td>19</td>
+<td><strong>13</strong></td>
+<td>-</td>
+<td>35</td>
+<td><strong>23</strong></td>
+<td>-</td>
+<td>51</td>
+<td><strong>33</strong></td>
+</tr>
+<tr>
+<td>4</td>
+<td><strong>04</strong></td>
+<td>-</td>
+<td>20</td>
+<td><strong>14</strong></td>
+<td>-</td>
+<td>36</td>
+<td><strong>24</strong></td>
+<td>-</td>
+<td>52</td>
+<td><strong>34</strong></td>
+</tr>
+<tr>
+<td>5</td>
+<td><strong>05</strong></td>
+<td>-</td>
+<td>21</td>
+<td><strong>15</strong></td>
+<td>-</td>
+<td>37</td>
+<td><strong>25</strong></td>
+<td>-</td>
+<td>53</td>
+<td><strong>35</strong></td>
+</tr>
+<tr>
+<td>6</td>
+<td><strong>06</strong></td>
+<td>-</td>
+<td>22</td>
+<td><strong>16</strong></td>
+<td>-</td>
+<td>38</td>
+<td><strong>26</strong></td>
+<td>-</td>
+<td>54</td>
+<td><strong>36</strong></td>
+</tr>
+<tr>
+<td>7</td>
+<td><strong>07</strong></td>
+<td>-</td>
+<td>23</td>
+<td><strong>17</strong></td>
+<td>-</td>
+<td>39</td>
+<td><strong>27</strong></td>
+<td>-</td>
+<td>55</td>
+<td><strong>37</strong></td>
+</tr>
+<tr>
+<td>8</td>
+<td><strong>08</strong></td>
+<td>-</td>
+<td>24</td>
+<td><strong>18</strong></td>
+<td>-</td>
+<td>40</td>
+<td><strong>28</strong></td>
+<td>-</td>
+<td>56</td>
+<td><strong>38</strong></td>
+</tr>
+<tr>
+<td>9</td>
+<td><strong>09</strong></td>
+<td>-</td>
+<td>25</td>
+<td><strong>19</strong></td>
+<td>-</td>
+<td>41</td>
+<td><strong>29</strong></td>
+<td>-</td>
+<td>57</td>
+<td><strong>39</strong></td>
+</tr>
+<tr>
+<td>10</td>
+<td><strong>0A</strong></td>
+<td>-</td>
+<td>26</td>
+<td><strong>1A</strong></td>
+<td>-</td>
+<td>42</td>
+<td><strong>2A</strong></td>
+<td>-</td>
+<td>58</td>
+<td><strong>3A</strong></td>
+</tr>
+<tr>
+<td>11</td>
+<td><strong>0B</strong></td>
+<td>-</td>
+<td>27</td>
+<td><strong>1B</strong></td>
+<td>-</td>
+<td>43</td>
+<td><strong>2B</strong></td>
+<td>-</td>
+<td>59</td>
+<td><strong>3B</strong></td>
+</tr>
+<tr>
+<td>12</td>
+<td><strong>0C</strong></td>
+<td>-</td>
+<td>28</td>
+<td><strong>1C</strong></td>
+<td>-</td>
+<td>44</td>
+<td><strong>2C</strong></td>
+<td>-</td>
+<td>60</td>
+<td><strong>3C</strong></td>
+</tr>
+<tr>
+<td>13</td>
+<td><strong>0D</strong></td>
+<td>-</td>
+<td>29</td>
+<td><strong>1D</strong></td>
+<td>-</td>
+<td>45</td>
+<td><strong>2D</strong></td>
+<td>-</td>
+<td>61</td>
+<td><strong>3D</strong></td>
+</tr>
+<tr>
+<td>14</td>
+<td><strong>0E</strong></td>
+<td>-</td>
+<td>30</td>
+<td><strong>1E</strong></td>
+<td>-</td>
+<td>46</td>
+<td><strong>2E</strong></td>
+<td>-</td>
+<td>62</td>
+<td><strong>3E</strong></td>
+</tr>
+<tr>
+<td>15</td>
+<td><strong>0F</strong></td>
+<td>-</td>
+<td>31</td>
+<td><strong>1F</strong></td>
+<td>-</td>
+<td>47</td>
+<td><strong>2F</strong></td>
+<td>-</td>
+<td>63</td>
+<td><strong>3F</strong></td>
+</tr>
+</tbody>
+</table></div>
+</body>
+
+</html>

+ 686 - 0
README.md

@@ -0,0 +1,686 @@
+  
+
+# Easy Nextion Library
+
+## Description
+
+A simple library that uses only four functions. You can easily benefit from Nextion's wide range of features and advantages in just a few easy steps. 
+The library uses a custom protocol that can prove to be a **powerful tool** for advanced users as it can be **easily modified** to meet one’s needs.
+This is an attempt to give a very simple method to use Nextion monitors for beginners at programming and at the same time to be a strong and reliable method that can be capable of satisfying the needs of the advance programming.
+The handling of Nextion should be as simple and at the same time as professional as a display of this kind deserves.
+
+I have invested time and resources providing open source codes, like this one. Please do not hesitate to support my work!
+If you found this work useful and has saved you time and effort, 
+just simply paypal me at this Link: [seithagta@gmail.com](https://paypal.me/seithan)
+
+You can find more examples, tutorials and projects with Nextion on my website [seithan.com](https://seithan.com/) or at my YouTube channel [Thanasis Seitanis](https://www.youtube.com/channel/UCk_AjYtvzUC58ups5Lm053g)
+
+## Installation 
+
+### First Method
+1.  In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
+1.  Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
+1.  Then search for EasyNextionLibrary using the search bar.
+1.  Click on the text area and then select the latest version and install it.
+
+![enter image description here](./extras/media/EasyNextionLibrary_Arduino_Library_Manager.png)
+
+### Second Method
+1. Download the latest release of EasyNextionLibrary.
+- From: [https://github.com/Seithan/EasyNextionLibrary](https://github.com/Seithan/EasyNextionLibrary)
+2. Extract the `.zip` file 
+3. Copy the EasyNextionLibrary folder, to: ....\Arduino\libraries\  
+
+
+***NOTE***: `.HMI` files for Nextion Editor are also included in every example's folder.
+All `.HMIs` are set for 2.8" Basic screens, so as to be easier to modify it for bigger screens.
+
+## The main functions
+- `begin();`
+- `writeNum();`
+- `writeStr();`
+- `readNumber();`
+- `trigger();`
+ - `readStr();` Added with version 1.0.4
+  
+***And the public variables:***
+* currentPageId (Data Type: **Integer**)
+* lastCurrentPageId (Data Type: **Integer**)
+
+ **Functions for user custom command protocol**
+ - `readByte();` Added with version 1.0.5
+ - `easyNexReadCustomCommand()` Added with version 1.0.5
+ and the public variables for user custom command protocol Added with version 1.0.5
+ - `cmdGroup` (Data Type: **Byte**)
+ - `cmdLength` (Data Type: **Byte**)
+
+### Details, examples and explanation on custom protocol, can be found on my website at: 
+#### [https://seithan.com/Easy-Nextion-Library/Custom-Protocol/](https://seithan.com/Easy-Nextion-Library/Custom-Protocol/)
+
+## 4-step Example
+1.  **Include** ***EasyNextionLibrary*** and create an object of `EasyNex` class
+````Cpp
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex > 
+                       // Set as parameter the Hardware Serial you are going to use
+````
+2.  **Begin the object** and give the desired baud rate as a parameter. Also, initialize the built-in LED as output
+````Cpp
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used 
+  pinMode(LED_BUILTIN, OUTPUT); // The built-in LED is initialized as an output                     
+}
+````
+3. **Place** the **NextionListen()** function in the loop.
+````Cpp
+void loop(){
+  myNex.NextionListen(); // This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+}
+````
+4. **Select one of the 50 predefined trigger()** functions and use it as a simple void function (nothing returned).
+Declare the void function by simply writing:
+````Cpp
+void trigger0(){
+[ put your code here !!!!]
+}
+````
+* Write the code you want to run in there.  
+The `trigger0()` function will run every time the following sequence of bytes (in HEX format) `23 02 54 00` comes to Arduino's Serial. To do that, write in the `Touch Release Event` of the button b0, this command: `printh 23 02 54 00`
+````Cpp
+void trigger0(){
+
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 
+  if(digitalRead(LED_BUILTIN) == HIGH){
+    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
+    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
+    
+  }else if(digitalRead(LED_BUILTIN) == LOW){
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
+  }
+}
+````
+Enjoy the Easy Nextion Library!! Please do not forget the LED on :)
+
+## Full Example Code
+````Cpp
+/*
+ * FourStepExample.ino - Simple example code
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex > 
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used 
+                     
+  pinMode(LED_BUILTIN, OUTPUT); // The built-in LED is initialized as an output                     
+}
+
+void loop(){
+  myNex.NextionListen(); // This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+}
+
+void trigger0(){
+  /* Create a button on Nextion
+   * Write in the Touch Release Event of the button
+   * this command:    printh 23 02 54 00
+   * Every time the button is pressed, the trigger0() function will run
+   * and the code inside will be executed once
+   */
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); //If LED_BUILTIN is ON, turn it OFF, or the opposite
+  if(digitalRead(LED_BUILTIN) == HIGH){
+    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
+    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
+    
+  }else if(digitalRead(LED_BUILTIN) == LOW){
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
+  }
+}
+````
+## Function documentation
+***The various combinations of attribute choices provide a wide range of expected behaviors with many combinations.  
+This combined with the Nextion Instruction Set creates the opportunity for very powerful HMIs.***
+
+***NOTE***:
+As these commands are using the Serial port to read and write, it is more preferred not to run them in the loop() without delay(); or some other method of not running them with the frequency of the loop and use them only when it is needed.
+Using them in a loop, a delay in the loop can be noticed, especially when reading from the Serial. A Serial buffer overflow can also be caused.
+***Also NOTE***: (from the Nextion Editor Guide)
+> In an HMI project a page is a localized unit. When changing pages, the existing page is removed from memory and the > > requested page is then loaded into memory. As such components with a variable scope of _**local**_ are only accessible while the page they are in is currently loaded. Components within a page that have a variable scope of _**global**_ are accessible by prefixing the page name to the global component .objname.
+As an Example:
+ A global Number component n0 on page1 is accessed by **page1.n0** . 
+A local Number component n0 on page1 can be accessed by page1.n0 or n0, but there is little sense to try access a local component if the page is not loaded. Only the component attributes of a global component are kept in memory. Event code is never global in nature.
+
+### Function trigger(); 
+**`Associated Library's Code Example:`** ***` Trigger`* **`and`** *`FourStepExample`***
+
+***Description:***
+This is the most important function of the library. 
+And this is because, it gives you the ability to use the predefined functions and run your code from there. 
+These predefined functions are named `trigger0()`, `trigger1()`, `trigger2()`... up to `trigger50()`. 
+You can use them as a simple void function out of the loop, in which you will have written a block of code to run every time it is called.
+You can call those `trigger()` functions and run the code they contain anytime by simply writing in a Nextion Event the command: `printh 23 02 54 XX` , where `XX` the id for the triggerXX() in HEX.
+For example in a button's Touch Release Event, write:
+|Command|Function|
+|--|--|
+|printh 23 02 54 00 |trigger0() |
+|printh 23 02 54 01 |trigger1() |
+|... |... |
+|printh 23 02 54 0A |trigger10() |
+|... up to |... up to |
+|printh 23 02 54 32 |trigger50() |
+
+In Arduino code, declare a void `trigger()` function with the predefined name you want to use and put your code there. 
+Declare the void function by simply writing:
+````Cpp
+void trigger0(){
+[ put your code here !!!!]
+}
+````
+Example:
+````Cpp
+#include "EasyNextionLibrary.h"
+
+EasyNex myObject(Serial);
+void setup(){
+  myObject.begin(9600);
+  pinMode(LED_BUILTIN, OUTPUT);
+}
+void loop(){
+  myObject.NextionListen();
+}
+void trigger0(){
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
+}
+````
+***1st NOTE***: To change the predefined names of the `trigger()` functions, there are details inside the `trigger.cpp` file and you can add up to **255** functions of this kind.
+***2nd NOTE***: You can send  the same `printh` command, to call the same function, from more than one component from any page, depending on your needs
+
+*See Appendix at the end of the document for numbers in HEX table*
+
+ ### Function begin();
+ 
+ ***Parameters:***
+ begin(``unsigned long``)
+**unsigned long**: unsigned long baud = **9600** (default) if nothing is written in the begin() function 
+
+ ***Description:***
+ **The begin()** method of the class in which we pass the initialization data to the objects. 
+
+ 
+ ***Syntax:*** 
+````Cpp 
+myObject.begin(115200); // for baud rate 115200
+ ````
+ 
+ ### Function writeNum();
+
+**`Associated Library's Code Example:` *`ReadAndWriteNumber`***
+
+  ***Parameters:***
+ writeNum(`String`, `uint32_t`) 
+ * **String** = objectname.numericAttribute (example: "n0.val"  or "n0.bco".....etc)
+ * **uint32_t** = value (example: 84)(number from 0 to 4,294,967,295)
+ 
+ ***Description:***
+ For writing numbers in numeric attributes in components of any kind (variables, textboxes,  etc.).  
+ * We can change the shown value of a number box
+ * We can change the value of a numeric attribute of the design editing commands. Those commands are used to change the attribute of the components (button, text box, timer, numeric etc.) while Nextion is running.
+
+|Command|Result on n0 comp.|Syntax|
+|--|--|--|
+|n0.val=30|Sets n0 component’s shown value to 30|`myObject.writeNum("n0.val", 30);`|
+|va0.val=30|Sets va0 variable's value to 30|`myObject.writeNum("va0.val", 30);`|
+|n0.bco=63488|Sets background color to red|`myObject.writeNum("n0.bco", 63488);`|
+|n0.font=0|Sets font to font style with Id = 0|`myObject.writeNum("n0.font", 0);`|
+|n0.pco=1055|Sets font color to blue|`myObject.writeNum("n0.pco", 1055);`|
+|n0.format=0|Sets value format to decimal|`myObject.writeNum("n0.format", 0);`|
+With the same way you can change the xcen, ycen, length and isbr
+
+***TIP:** In a timer component, at the attribute < **en** >, you can start or stop the timer by writing **0** or **1**.*
+Also, at the attribute < **tim** >, you can set the time the timer is going to repeat the commands written in timer's User-code event.
+````Cpp
+myObject.writeNum("tm0.en", 0);     // 0 = stop, 1 = start
+myObject.writeNum("tm0.tim", 1000); // repeat code every 1000ms
+````
+
+ ***Syntax:***
+````Cpp
+myObject.writeNum("n0.val", 30);    // Set the value of numeric n0 to 30
+myObject.writeNum("n0.bco", 63488); // Set background color of n0 to 63488(red)
+myObject.writeNum("n0.font", 0);    // Set font to font style with ID 0
+myObject.writeNum("n0.pco", 1055);  // Set font color to blue
+myObject.writeNum("n0.format", 0);  // Set value format to decimal
+````
+***NOTE:** Only attributes shown in green in the Editor can be both read and changed by user code at runtime.*
+![Attribute panel](./extras/media/AttributePane.png)
+
+
+ ### Send floating-point numbers, a number that has a decimal point.
+### Or send a number on a textbox
+
+
+***Description:***
+Nextion **DOES NOT SUPPORT** float numbers. Instead, it uses integer math and does not have real or floating support.
+The Xfloat component is used for signed 32-bit integer values.
+The `.vvs0` sets the number of digits shown to the left of the decimal (useful for leading zeros).
+The `.vvs1` sets the number of digits shown to the right of the decimal.
+
+***You can send Floating-point numbers with these two ways***:
+* On a **Xfloat component** after you convert the float to int and multiply it by 10, the Xfloat component will put a comma `,` (decimal point) automatically after the last digit  if attribute `vvs1` is set to 1.
+
+***Example:***
+````Cpp
+int tempInt = temperature*10;      // Convert the float to int. Multiply it x10                       
+myNex.writeNum("x0.val", tempInt); // Write it to x0 Xfloat component on Nextion
+````
+it is obvious that if you want 2 decimal places, you will set the attribute `vvs1` to `2` and you will multiply by `100`
+* On a **Textbox component** after you convert the float value to String
+
+***Example:***
+````Cpp
+String tempString = String(temperature, 1); // Convert the float value to String, with 1 decimal place
+myNex.writeStr("t0.txt", tempString);       // Write the String value to t0 Textbox component
+````
+                                  
+### Function writeStr();
+
+**`Associated Library's Code Example:` *`WriteTextAndCommands`***
+
+***Parameters:***
+- writeStr(`String`, `String`). *To change the `.txt` attribute in components*
+**String No1**: objectname.textAttribute (example: "t0.txt"  or "b0.txt")
+**String No2**: value (example: "Hello World")
+
+- writeStr(`String`). *To send Designing and System Commands*
+**String**: The command to send on Nextion
+
+***Description:***
+For writing text in Nextion. The two ways the command can be used:
+
+**First Usage of the command**:
+Use **writeStr(** `String`, `String` **)** to change the text in a textbox 
+Use both parameters to write text in textboxes. 
+   * In the first parameter, write the objectName.textAttribute example: t0.txt or b0.txt
+   * In the second parameter, write the text you want to "print"
+
+***1st Syntax:***
+````Cpp
+myObject.writeStr("t0.txt", "Hello World"); // Change t0 text to "Hello World"
+````
+Any previous text on the textbox is deleted
+
+Avoid using very big text Strings in the same command, as Nextion will not recognise them. Istead use a second command and in order to add to the existing text, use the **`+`** symbol, after the `.textAttribute("t0.txt+")`.
+````Cpp
+myObject.writeStr("t0.txt", "You are now transferred to page2\\rThank you\\rfor choosing my library!!!");
+myObject.writeStr("t0.txt+", "\\rEnjoy the library!!!");
+myObject.writeStr("t0.txt+", "\\r\\rAthanasios Seitanis\\rseithagta@gmail.com");
+  /* By writing \\r, you send Nextion the change line character < \r >
+   * The second \ is required, in order to print the \ as character
+   * and not as an escape character.
+   */
+````
+
+**Second Usage of the command**:
+Use **writeStr(** `String` **)** to send Designing and System Commands according to the instructions of Nextion's Instruction Set.
+Use only the first parameter to send a command to Nextion. The commands must be syntaxed according to Nextion's Instruction Set.
+
+***2nd Syntax:***
+***Design Commands Example:***
+````Cpp
+myObject.writeStr("page page0"); // Sending this command to change the page we are on Nextion using pageName
+myObject.writeStr("page 1"); // Sending this command to change the page we are on Nextion using pageId
+````
+
+````Cpp
+myObject.writeStr("cir 100,100,30,RED"); // Renders a hollow Red circle with circle center at (100,100)
+````
+***System Commands Example:***
+````Cpp
+myObject.writeStr("dim=50"); // Set the current brightness level to 50%
+````  
+````Cpp
+myObject.writeStr("sleep=1"); // sleep=1 (Enter sleep mode) or sleep=0 (Exit sleep mode)
+````  
+***NOTE**: When you decide to exit the sleep mode on Nextion, use a small delay of 50ms, in order to give Nextion some time to Exit sleep mode.*
+***WARNING**: DO NOT send commands that causes data return over Serial to MCU, unless you know what you are doing.* 
+Commands that cause data return over serial:
+`print`, `prints`, `printh`, `sendme`, `get`, `rept`, `rdfile`, `twfile`
+***TIP**: Write in the debug mode the command to check if it is written correctly*
+
+### Function readNumber();
+
+**`Associated Library's Code Example:` *`ReadAndWriteNumber`***
+
+***Parameters:***
+readNumber(`String`)
+* **String**: objectname.numericAttribute (example: "va0.val" "n0.val", "n0.pco", "n0.bco"...etc)
+
+***Description:***
+We use it to read the value of every components' numeric attribute from Nextion (value, bco color, pco color...etc)
+
+
+In case the function fails to read the new value, it will return the number `777777`. 
+The reasons of getting `777777`: (from release 1.0.2 and above)
+   -  Waiting bytes have not come to Serial timeout
+   - Command start character is not found in Serial timeout
+   - The waiting length of the byte package has not come to Serial
+   - Bytes on Serial are not the expected
+The chances of getting a wrong value is one in a million.
+You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value. 
+You can check it with an **`if()`** statement, in which you will ignore the value of `777777` and you can run the `readNumber()` again or set a safe value or use the last good known value method.
+
+````Cpp
+uint32_t number = 0;
+uint32_t lastnumber = 0;
+
+number = myNex.readNumber("n0.val");   // We read the value of n0 and store it to number variable
+    
+if(number != 777777){       // 777777is the return value if the code fails to read the new value
+  lastnumber = number;
+  
+} else if(number == 777777){
+    number = lastNumber;
+}
+````
+
+***Syntax:***
+````Cpp
+unsigned long x = myObject.readNumber("n0.val"); // Store to x the value of numeric box n0
+unsigned long x = myObject.readNumber("va0.val"); // Store to x the value of the variable va0
+unsigned int y = myObject.readNumber("b0.bco"); // Strore to y the color number of the background of button b0
+````
+***NOTE:** Only attributes shown in **green** in the Editor can be both read and changed by user code at runtime.*
+To 
+
+### Function readStr();
+
+**`Associated Library's Code Example:` *`ReadString`***
+
+***Parameters:***
+readStr(`String`)
+* **String**: objectname.textAttribute (example: "t0.txt", "va0.txt", "b0.txt"...etc)
+
+***Description:***
+We use it to read the value of every components' text attribute from Nextion (txt etc...)
+
+In case the function fails to read the new value, it will return the text `ERROR`. 
+The reasons of getting `ERROR`: (from release 1.0.4 and above)
+   -  Serial buffer occupied timeout
+   -  Waiting bytes have not come to Serial timeout
+   - Command start character is not found in Serial timeout
+   - The end of the command has not come to Serial
+   
+The chances of getting a wrong value is one in a million.
+You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value. 
+You can check it with an **`if()`** statement, in which you will ignore the value of `ERROR` and you can run the `readStr()` again or set a safe value or use the last good known value method.
+
+````Cpp
+String text = "";
+String lastText = "";
+
+text = myNex.readStr("t0.txt");   // We read the value of t0 and store it
+    
+if(text.equals("ERROR") == false){       // ERROR is the return value if the code fails to read the new value
+  lastText = text;
+  
+} else if(text.equals("ERROR") == true){
+    text = lastText;
+}
+````
+
+***Syntax:***
+````Cpp
+String x = myObject.readStr("t0.txt"); // Store to x the value of text box t0
+````
+
+##  Library Public Variables
+
+**`Associated Library's Code Example:` *` ChangePagesAndSentFloatValues`***
+
+***1st Variable***:
+*currentPageId*
+A variable that stores the ID number of the current page loaded on Nextion. It is **VERY** important that Nextion and Arduino are synced and when you send data, the data goes to the right page.
+
+**NOTE**: In order to update this variable with the current Id of the page, you must write the Preinitialize Event of every page: `printh 23 02 50 XX` , where `XX` the id of the page in HEX.  
+For page0: `printh 23 02 50 00`
+for page9: `printh23 02 50 09`
+for page10: `printh 23 02 50 0A`
+
+*See Appendix at the end of the document for numbers in HEX table*
+
+It can be called by writing:
+````Cpp
+int x = myObject.currentPageId; // Store to x the currentPageId
+````
+**Example**:
+````Cpp
+if(myObject.currentPageId == 0){
+  myObject.writeStr("t0.txt", "You are on page0!");
+}else if(myObject.currentPageId == 1){
+  myObject.writeStr("t0.txt", "You are on page1!");
+}
+````
+
+***2nd Variable***:
+*lastCurrentPageId*
+This variable stores the last value of `currentPageId` before `currentPageId` is changed. We use it to check if the page we are on has changed, in order to send refreshing screen data to the components of the page. 
+
+After that, it can be set to equal with the `currentPageId`, in order not to send unnecessary data for refreshing the components.  
+
+````Cpp
+if(myObject.currentPageId != myObject.lastCurrentPageId){
+  if(myObject.currentPageId == 0){
+    [send the data to refresh the page0]
+  }else if(myObject.currentPageId == 1){
+    [send the data to refresh the page1]
+  }
+  myObject.lastCurrentPageId = myObject.currentPageId;
+}
+````
+Find more on the Library's Example:  *`ChangePagesAndSentFloatValues`*
+***TIP**: You can read the ID of the current Loaded page at anytime, without the use of the Library's commands using the `dp` system command*
+````Cpp
+int x = myObject.readNumber("dp"); // Store to x the ID of the current Loaded page
+````
+
+###  Function easyNexReadCustomCommand()
+`easyNexReadCustomCommand()` has a weak attribute and will be created only when user
+declares this function in the main code.
+More for custom protocol and commands https://seithan.com/Easy-Nextion-Library/Custom-Protocol/
+ Our commands will have this format: `#`  `len`   `cmd`   `id`   `id2` 
+ and we must send them from Nextion as HEX with the printh command.
+For example: `printh 23 03 4C 01 01`
+- `#` start marker, declares that a command follows
+- `len` declares the number of bytes that will be received
+ - `cmd` declares the task of the command or command group
+- `id` declares the properties of the command
+- `id2` a second property for the command
+
+When we send a custom command with the above format, the function NextionListen() will capture the start marker `#` and the `len` (first 2 bytes) and it will wait until all the bytes of the command, as we have declared with the `len` byte, arrive to the Serial buffer and inside the timeout limits.
+After that, the function will read the next byte, which is the command group and the function `readCommand()` takes over and through a switch command tries to match the `_cmd` variable that holds the command group value with the statements of the cases.
+If we do NOT have a match with the predefined, `cmd` of `P` for page and `T` for triggers, it will continue to the default where we store the `_cmd` and `_len` to the public variables `cmdGroup` and `cmdLenght` as we are going to need access to them from the main code in the next step.
+Next we call the the `easyNexReadCustomCommand()`  with the precondition and ONLY if we have declared the function in the main code.
+From this point we can handle the assign of `cmdGroup` and `IDs` from the `easyNexReadCustomCommand()` in the user code, where we can go on with a switch case
+for the `cmdGroup`, the one that we have stored the `_cmd` for public use and we can call it with `myObject.cmdGroup`. This is why we made `cmdGroup` a public variable.
+
+As an example, we use 2 arrays (tables) of integers, where we are going to change the value of the position (element) with custom commands.
+````Cpp
+ int dataL[4] = {0,0,0,0}; //values 0 or 255, because we use only one byte
+ int dataS[4] = {0,0,0,0}; // values from 0 to 255, because we use only one byte
+````
+The format is the known: `#`  `len`   `cmd`   `id`   `id2` 
+- where the `id` referred to the position (element) of the array we want to write on
+- And `id2` carries the value to be written on the element of array. 
+
+The custom command from Nextion: `printh 23 03 4C 00 0A`
+- 4C is the Hex for letter L and we refer to the array `dataL[]`
+- 00 Hex of Dec number 0 used as the index for each array element
+- 0A Hex of Dec number 10 is the value we are going to write on element 0
+
+After the command is executed by our code, the values on `dataL[]` array will be
+- dataL[4] = {10,0,0,0}
+
+Same for the dataS[] intead that cmd is the 53 in Hex for letter `S`
+
+````Cpp
+void easyNexReadCustomCommand(){
+
+  int arrayPlace; // temp variable
+  int value;      // temp variable
+  
+  switch(myNex.cmdGroup){
+    
+    case 'L': // Or <case 0x4C:>  If 'L' matches
+    // we are going to write values in specific places in the dataL[] table
+    // read the next byte that determines the position on the table
+    arrayPlace = myNex.readByte();
+    
+    // read the next byte that keeps the value for the position
+    value = myNex.readByte();
+    
+    // update the array with the new values
+    dataL[arrayPlace] = value;  
+    
+    break; 
+
+    case 'S': // Or <case 0x53:>  If 'S' matches 
+    
+    // we are going to write values in specific places in the dataS[] table
+    // from Nextion printh 23 03 53 00 00
+    // read the next byte that determines the position on the table
+    arrayPlace = myNex.readByte();
+    
+    // read the next byte that keeps the value for the position
+    value = myNex.readByte();
+    
+    // update the array with the new values
+    dataS[arrayPlace] = value;  
+    
+    break;
+  }  
+}
+````
+##  Usefull Tips
+
+**Manage Variables**
+You can read/write the variables as any other component.
+
+Use `readNumber()` to read the value of a numeric variable.  
+Example: `myNex.readNumber("va0.val");`  
+**BUT:**  `myNex.readNumber("sys0");`
+
+Use `writeNum()` to change the value of a numeric variable.  
+Example: `myNex.writeNum("va0.val", 255);`  
+**BUT:**  `myNex.readNumber("sys0", 375);`
+
+Use `readStr()` to read the text of a String variable.  
+Example: `myNex.readStr("va0.txt");`
+
+Use `writeStr()` to change the text of a String variable.  
+Example: `myNex.writeStr("va0.txt", "Hello World");`
+For this to happen, the variables you want to read/write must be at the page you are currently on.  
+Otherwise, if the variables are of **global** scope, you will need to use a prefix with the page name that the variables are at.  
+Example:  
+`myNex.readNumber("page0.va0.val");` // If the variable is at page0  
+The same goes for the other functions as well.
+
+## Compatibility
+* Arduino
+* ESP
+
+Tested MCUs:
+1. Arduino NANO
+2. Arduino MEGA 2560
+3. Arduino UNO
+4. WeMos D1 mini ESP8266
+
+## Releases:
+
+### Release 1.0.6
+- Corrected line 264 of EasyNextionLibrary.cpp, where the "=" should be "==".
+````Cpp
+if(_endOfCommandFound == true)
+````
+Thank you Denis, Gixy31
+
+### Release 1.0.5
+- Updated `readNumber()` function for faster response and more accurate reading.
+- Added the `readByte()` function for reading  Serial buffer from user code
+- Added `easyNexReadCustomCommand()` function with a weak attribute and will be created only when user declares this function in the main code. The motivation to move this function out of the library's files, comes from Ricardo Reis thanks to his issue https://github.com/Seithan/EasyNextionLibrary/issues/15
+- Added public variables `cmdGroup` and `cmdLength` **ONLY** for read custom commands, stores the command group ID and the length of the command
+
+### Release 1.0.4
+- Added the readStr() function for reading a String from Nextion
+
+### Release 1.0.3
+
+Two more examples were added. 
+- The first one demonstrates how to use EasyNextionLibrary with waveforms. 
+- The  second one demonstrates how to use EasyNextionLibrary with progress bars
+
+### Release 1.0.2
+
+ - Remove the private function `readCommand()` from the main `EasyNextionLibrary.cpp` file. A new file is created named `readCustomCommands.cpp`,  in order to make easier the modifications for it when using the custom protocol.
+ - Return Error code added and to other cases of `readNumberFromSerial()`. When failing to read a number, we  return the number 777777 instead. The cases of having a 777777 return:
+   -  Waiting bytes have not come to Serial timeout
+   - Command start character is not found in Serial timeout
+   - The waiting length of the byte package has not come to Serial
+   - Bytes on Serial are not the expected
+ - The function readNumberFromSerial() is improved, making reading values more accurate, due to hardware or Serial problems.
+
+## Licence 
+This library is licensed under **MIT X11 license**.
+Copyright (C) <2020>  Athanasios Seitanis
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Athanasios Seitanis or the name of EasyNextionLibrary shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Athanasios Seitanis.
+Also, prior written permission is required if this software or any part of it or any modifications of it, are used for commercial purposes.
+
+By using this software, you agree with the above terms and conditions as they are.
+The owner of the software has the right to change the terms of this license at any time without a prior notification.
+
+## Appendix
+
+### Numbers in HEX:
+
+| DEC | HEX |-| DEC | HEX |-| DEC | HEX |-| DEC | HEX |  
+|--|--|--|--|--|--|--|--|--|--|--|
+| 0 | **00** |-| 16 | **10** |-| 32 | **20** |-| 48 | **30** |
+| 1 | **01** |-| 17 | **11** |-| 33 | **21** |-| 49 | **31** |
+| 2 | **02** |-| 18 | **12** |-| 34 | **22** |-| 50 | **32** |
+| 3 | **03** |-| 19 | **13** |-| 35 | **23** |-| 51 | **33** |
+| 4 | **04** |-| 20 | **14** |-| 36 | **24** |-| 52 | **34** |
+| 5 | **05** |-| 21 | **15** |-| 37 | **25** |-| 53 | **35** |
+| 6 | **06** |-| 22 | **16** |-| 38 | **26** |-| 54 | **36** |
+| 7 | **07** |-| 23 | **17** |-| 39 | **27** |-| 55 | **37** |
+| 8 | **08** |-| 24 | **18** |-| 40 | **28** |-| 56 | **38** |
+| 9 | **09** |-| 25 | **19** |-| 41 | **29** |-| 57 | **39** |
+| 10 | **0A** |-| 26 | **1A** |-| 42 | **2A** |-| 58 | **3A** |
+| 11 | **0B** |-| 27 | **1B** |-| 43 | **2B** |-| 59 | **3B** |
+| 12 | **0C** |-| 28 | **1C** |-| 44 | **2C** |-| 60 | **3C** |
+| 13 | **0D** |-| 29 | **1D** |-| 45 | **2D** |-| 61 | **3D** |
+| 14 | **0E** |-| 30 | **1E** |-| 46 | **2E** |-| 62 | **3E** |
+| 15 | **0F** |-| 31 | **1F** |-| 47 | **2F** |-| 63 | **3F** |
+
+
+
+<!--stackedit_data:
+eyJoaXN0b3J5IjpbLTYyNDQ3ODI2NSwtMTg1NDgxODkzMSw5Mz
+kxNzQxNzMsLTE4MDQwOTg1NDddfQ==
+-->

BIN
examples/AnalogRead To Progress Bar/AnalogRead To Progress Bar.HMI


+ 139 - 0
examples/AnalogRead To Progress Bar/AnalogReadToProgressbarCode/AnalogReadToProgressbarCode.ino

@@ -0,0 +1,139 @@
+
+/*
+ * AnalogReadToProgressbarCode.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+ /* This example aims to show how you can use and manage progress bar
+  * on Nextion displays and change it's value. 
+  * As example we are going to display the value of an analog input.
+  */
+  
+  //********** Progress bar's value data range is min 0 max 100 **********
+  //         **** A re-map of value range must de done ****
+  
+  /* To update the value of a progress bar you can use the writeNum() function
+   * writeNum("j0.val", 55); set the value of j0(object Name) to 55
+   * writeNum("j0.val", volt); set the value of j0(object Name) equal with the value of volt variable
+  */
+  
+  /* To make a vertical progress bar set the **dez** attribute to vertical 
+   * And change the values of width and height of the progress bar.
+   */
+  
+  /* To reverse the direction of progress bar where the default in horizontal is: left to right
+   * and down to up in vertical align, subtract the value from 100 and reverse the colors
+   * of foreground and background between them
+   */   
+   
+   /* There is no need to send the value from Arduino straight to the progress bar with writeNum();
+    * as most times the progress bar is not the only component on a page that must be updated
+    * usually the display of the value on a box also needed 
+    * On some cases a  change of color on a box or on progress bar also needed when value reach a point.
+    * As the value of the progress bar must be re-mapped to 0-100 and in order to not send the same value multiple times
+    * with different formats and limit the data from Serial, use the advantages of Nextion graphics to
+    * create a variable and save there the value you want to appear in the progress bar.
+    * Use the features provided by Nextion via the user code on a timer to update the progress bar 
+    * and at the same time display the value or whatever else you need.
+    */
+    
+
+#include "EasyNextionLibrary.h" // Include EasyNextionLibrary
+
+EasyNex myNex(Serial);   // Create an object of EasyNex class with the name < myNex >
+                        // Set as parameter the Hardware Serial you are going to use
+                        
+uint16_t voltage;  // a variable to store the reading
+                 // for simplicity Reasons we do not use float and we are going to take the measure in millivolts
+ 
+
+const int REFRESH_TIME = 100;           // time to refresh the Nextion page every 100 ms
+unsigned long refresh_timer = millis();  // timer for refreshing Nextion's page
+
+
+
+void setup() {
+
+  pinMode(A0, INPUT); // set A0 pin as INPUT
+ 
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+
+}
+
+void loop() {
+  
+  if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
+                                              // or an if statement with a timer condition like this one.
+                                              
+      int tempData = analogRead(A0);  // Read the analog pin
+      voltage = map(tempData, 0, 1024, 0, 5000); // same like: voltage = analogRead(A0)*5000/1024
+    
+      /* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
+       * connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
+       * https://www.arduino.cc/en/tutorial/potentiometer
+       * Turn it over and read values from 0 to 5000 millivolts
+       */
+               
+      myNex.writeNum("Nvoltage.val", voltage); // Nvoltage.val is a variable that we have create on Nextion.        
+                                              // we send the value of the voltage variable on Arduino
+                             // you can use the same name for variables on Nextion for easy recognition with a capital N in front
+                             // Avoid the use of big variable names as every character is one byte to serial. 
+                             // In here we use big names for the sake of example.
+      refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
+     
+    }       
+}
+
+/* The rest work is on Nextion with the code on a timers user event
+
+n0.val=Nvoltage.val         // write Nvoltage.val to n0.val
+sys0=Nvoltage.val*100/5000  // use sys0 to make the calculations
+j0.val=sys0                //  add the value to the Progress bar
+//
+//Reverse direction progress bar
+j1.val=100-sys0
+//
+// Vertical allign
+j2.val=sys0
+//
+// Progress bar can take values from 0-100
+// we map the value from arduino 0-5000 :
+// the math type for map the range is:
+// return = (value - low1) * (high2 - low2) / (high1 - low1) + low2
+// as both ranges start from zero low1 and low2 = 0
+// the type becomes
+// return = value*hight2/hight1
+// return=value*100/5000
+
+//
+// And some graphic effects
+if(n0.val>3300)
+{
+  n0.bco=RED
+  j0.pco=RED
+  j1.bco=RED //bco for the reversed
+  j2.pco=RED
+}else
+{
+  n0.bco=YELLOW
+  j0.pco=1024
+  j1.bco=1024
+  j2.pco=1024
+}
+*/
+

BIN
examples/AnalogRead To Waveform/AnalogRead To Waveform.HMI


+ 131 - 0
examples/AnalogRead To Waveform/AnalogReadToWaveformCode/AnalogReadToWaveformCode.ino

@@ -0,0 +1,131 @@
+
+/*
+ * AnalogReadToWaveformCode.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+ /* This example aims to show how you can use and manage single waveform
+  * on Nextion displays. As an example we are going to display the value of an analog input.
+  * With the same way you can manage more than one channels or waveforms
+  */
+  
+  /* Every waveform can have up to 4 channels. They are numbered from 0 to 3
+   * Don't mistake the number of channels with the ID of the channel
+   * ID is 0 for the first channel, 1 for the second, 2 for the third, 3 for the fourth  
+  */
+  //********** Waveform's channel data range is min 0 max 255 **********
+  //         **** A re-map of value range must de done ****
+  /* The command to Add single value to Waveform Channel is:
+   * add <waveform>,<channel>,<value>
+   * <waveform> is the .id of the waveform component
+   * <channel> is the channel the data will be added to
+   * <value> is ASCII text of data value, or numeric value
+   */
+   
+   /* TIP: Waveform 1 pixel column used for every data value added on x - axis
+    * on y - axis as the Data range is from 0 to 255 the height of waveform must be 255 pixel
+    * in order to have a represent of zero to the lower point and 255 to the higher point of the waveform
+    * If the height of the waveform is not 255 pixel use the * dis * attribute for scaling the data from 10 to 1000%
+    * if waveform has a height of 127 pixel set data scaling * dis * to 50. Set dis to 200 for 510 pixel waveform height
+    * You can use this math type < dis = 100*(waveform height in pixels)/255 >
+    */
+   
+   /* There is no need to send from Arduino the command add <waveform>,<channel>,<value>
+    * as most times the waveform is not the only component on a page that must be updated
+    * usually the display of the value on a box also needed 
+    * On some cases a  change of color on a box also needed when value reach a point.
+    * As the value to waveform must be re-mapped to 0-255 and in order to not send the same value multiple times
+    * with different formats and limit the data from Serial, use the advantages of Nextion graphics to
+    * create a variable and save there the value you want to appear in the waveform.
+    * Use the features provided by Nextion via the user code on a timer to update the waveform 
+    * and at the same time display the value or whatever else you need
+    */
+
+#include "EasyNextionLibrary.h" // Include EasyNextionLibrary
+
+EasyNex myNex(Serial);   // Create an object of EasyNex class with the name < myNex >
+                         // Set as parameter the Hardware Serial you are going to use
+                        
+uint16_t voltageGraph;   // a variable to store the reading
+                 // for simplicity reasons, we do not use float and we are going to take the measure in millivolts
+ 
+
+const int REFRESH_TIME = 100;           // time to refresh the Nextion page every 100 ms
+unsigned long refresh_timer = millis();  // timer for refreshing Nextion's page
+
+
+
+void setup() {
+
+  pinMode(A0, INPUT); // set A0 pin as INPUT
+ 
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+
+}
+
+void loop() {
+  
+  if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
+                                              // or an if statement with a timer condition like this one.
+                                              
+      int tempData = analogRead(A0);  // Read the analog pin
+      voltageGraph = map(tempData, 0, 1024, 0, 5000); // same like: voltageGraph = analogRead(A0)*5000/1024
+    
+      /* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
+       * connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
+       * https://www.arduino.cc/en/tutorial/potentiometer
+       * Turn it over and read values from 0 to 5000 millivolts
+       */
+               
+      myNex.writeNum("NvoltageGraph.val", voltageGraph); // NvoltageGraph.val is a variable that we have create on Nextion.        
+                                                        // we send the value of the voltageGraph variable on Arduino
+                             // you can use the same name for variables on Nextion for easy recognition with a capital N infront
+                             // Avoid the use of big variable names as every character is one byte to serial. 
+                             // In here we use big names for the sake of the example.
+      refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
+     
+    }        
+}
+
+/* The rest work is on Nextion with the code on a timers user event
+
+   sys0=NvoltageGraph.val*255/5000  // use sys0 to make the calculations
+   add 2,0,sys0                  // add the value to the waveform with id=2 at first channel (0) 
+   n0.val=NvoltageGraph.val      // write NvoltageGraph.val to n0.val
+ //
+ // Waveform can take values from 0-250
+ // we map the value from arduino 0-5000 :
+ // the math type for map the range is:
+ // return = (value - low1) * (high2 - low2) / (high1 - low1) + low2
+ // as both ranges start from zero low1 and low2 = 0 
+ // the type becomes
+ // return = value*hight2/hight1
+ // return=value*255/5000
+ //
+ 
+ 
+ // And some graphic effects
+if(n0.val>3300)
+{
+  n0.bco=RED
+}else
+{
+  n0.bco=YELLOW
+}
+*/
+

BIN
examples/ChangePagesAndSendFloatValues/ChangePagesAndSendFloatValues.HMI


+ 294 - 0
examples/ChangePagesAndSendFloatValues/ChangePagesAndSendFloatValuesCode/ChangePagesAndSendFloatValuesCode.ino

@@ -0,0 +1,294 @@
+/*
+ * ChangePagesAndSentFloatValuesCode.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ // https://www.seithan.com 
+ //********************************************************************************
+
+// Compatible for Arduino and WeMos D1 mini
+ 
+/* This project aims to show how to manage page changes,
+ * how to send different data in different pages and 
+ * how to limit the data sent to Nextion to minimum
+ * and to avoid unnecessary use of the Serial and 
+ * a possible buffer overflow.
+ */
+ 
+/* This project also demonstrates the two ways you can send float values
+ * on Nextion, as Nextion DOES NOT SUPPORT float numbers. Uses integer math
+ * and does not have real or floating support.
+ * The Xfloat component is used for signed 32-bit integer values. 
+ * The .vvs0 sets the number of digits shown to the left of the decimal (useful for leading zeros). 
+ * The .vvs1 sets the number of digits shown to the right of the decimal. 
+ * Go to the refreshPage0() function and see the comments on how we can send float values 
+ */
+ 
+/* The best way to demonstrate the change of the pages,
+ * is to use the DHT11 sensor, as it is very common and
+ * the chances of someone having one, are very high.
+ * Also, it gives us at least 3 different types of data.
+ * DHT11, DHT21 or DHT22 can be used.
+ */
+ 
+//---------------------------------- 
+// EasyNextionLibrary Initialization
+//---------------------------------- 
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+
+//--------------------------------------
+// DHT Library and Sensor Initialization
+//--------------------------------------
+// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
+
+#include "DHT.h"   // Include DHT library
+
+#define DHTPIN 2   // Digital pin connected to the DHT sensor D2 for UNO, NANO, MEGA,  D4 for WeMos D1 mini
+
+// Uncomment whatever type you're using!
+#define DHTTYPE DHT11       // DHT 11
+//#define DHTTYPE DHT22     // DHT 22  (AM2302), AM2321
+//#define DHTTYPE DHT21     // DHT 21 (AM2301)
+
+#define GET_DATA_EVERY 2000 // DHT sensors can give us measurements every 2 seconds,
+                            // as Adafruit suggests
+                            
+unsigned long getDataTimer = millis(); // Timer for GET_DATA_EVERY 
+
+DHT dht(DHTPIN, DHTTYPE);
+
+// Reading temperature or humidity takes about 250 milliseconds!
+
+// We create the lastXX value variables, in order to store the last value that we have sent on Nextion,
+// compare the last value with the new value (current value that we have take from sensor) and send 
+// the new value ONLY if it is different from the last and not send data to Nextion if there is no need.
+
+// For the needs of this project, the last value comparison might be not needed,
+// but I write these, just to show how you can do it, if it is really needed, at more complicated projects.
+
+float humidity = 0.0;     // Store the value of humidity
+float lastSentHumidity = 0.0; // Store the last value of humidity that we have Sent on Nextion
+
+float temperature = 0.0;     // Store the value of the temperature in Celsius
+float lastSentTemperature = 0.0; // Store the last value of the temperature in Celsius that we have sent on Nextion
+
+float fahrenheit = 0.0;     // Store the value of the temperature in Fahrenheit
+float lastSentFahrenheit = 0.0; // Store the last value of the temperature in Fahrenheit that we have sent on Nextion
+
+float heatIndexFahrenheit = 0.0;     // Store the value of the heat index in Fahrenheit
+float lastSentHeatIndexFahrenheit = 0.0; // Store the last value of the heat index in Fahrenheit that we have sent on Nextion
+
+float heatIndexCelsius = 0.0;     // Store the value of the heat index in Celsius
+float lastSentHeatIndexCelsius = 0.0; // Store the last value of the heat index in Celsius that we have sent on Nextion
+
+//---------------------------------- 
+// Change Page Initialization
+//---------------------------------- 
+
+/* In order to update currentPageId variable with the current Id of the page, 
+ * you must write at the Preinitialize Event of every page: `printh 23 02 50 XX` , where `XX` the id of the page in HEX.  
+ *      For page0: `printh 23 02 50 00`
+ *      For page9: `printh23 02 50 09`
+ *      For page10: `printh 23 02 50 0A`
+ */
+#define DATA_REFRESH_RATE 1000 // The time between each Data refresh of the page
+                               // Depending on the needs of the project, the DATA_REFRESH_RATE can be set
+                               // to 50ms or 100ms without a problem. In this example, we use 1000ms, 
+                               // as DHT sensor is a slow sensor and gives measurements every 2 seconds
+
+unsigned long pageRefreshTimer = millis(); // Timer for DATA_REFRESH_RATE
+
+bool newPageLoaded = false; // true when the page is first loaded ( lastCurrentPageId != currentPageId )
+
+ 
+void setup(){
+
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used 
+  dht.begin();
+  
+  delay(500);               // give Nextion some time to finish initialize
+  myNex.writeStr("page 0"); // For synchronizing Nextion page in case of reset to Arduino
+  delay(50);
+  myNex.lastCurrentPageId = 1; // At the first run of the loop, the currentPageId and the lastCurrentPageId
+                               // must have different values, due to run the function firstRefresh()
+}
+
+void loop(){
+
+  myNex.NextionListen(); // This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+  readSensorValues();
+  
+  refereshCurrentPage();
+  
+  firstRefresh();
+  
+}
+
+void firstRefresh(){ // This function's purpose is to update the values of a new page when is first loaded,
+                     // and refreshing all the components with the current values as Nextion shows the Attribute val.
+
+  if(myNex.currentPageId != myNex.lastCurrentPageId){ // If the two variables are different, means a new page is loaded.
+    
+    newPageLoaded = true;    // A new page is loaded
+                             // This variable is used as an argument at the if() statement on the refreshPageXX() voids, 
+                             // in order when is true to update all the values on the page with their current values
+                             // with out run a comparison with the last value.
+    
+    switch(myNex.currentPageId){
+      case 0:
+        refreshPage0();
+        break;
+      
+      case 1:
+        refreshPage1();
+        break;
+        
+      case 2:
+        refreshPage2();
+        break;
+        
+      case 3:
+        refreshPage3();
+        break;
+    }
+    
+    newPageLoaded = false;  // After we have updated the new page for the first time, we update the variable to false.
+                            // Now the values updated ONLY if the new value is different from the last Sent value.
+                            // See void refreshPage0()
+    
+    myNex.lastCurrentPageId = myNex.currentPageId; // Afer the refresh of the new page We make them equal,
+                                                   // in order to identify the next page change.
+  }
+}
+
+void readSensorValues(){
+
+  if((millis() - getDataTimer) > GET_DATA_EVERY){
+  
+    humidity = dht.readHumidity(); // Read relative humidity
+    
+    temperature = dht.readTemperature(); // Read temperature as Celsius (the default)    
+    fahrenheit = dht.readTemperature(true);// Read temperature as Fahrenheit (isFahrenheit = true)
+    
+    heatIndexFahrenheit = dht.computeHeatIndex(fahrenheit, humidity);// Compute heat index in Fahrenheit (the default)
+    heatIndexCelsius = dht.computeHeatIndex(temperature, humidity, false); // Compute heat index in Celsius (isFahreheit = false)
+    
+    getDataTimer = millis();
+    
+  }
+}
+
+void refereshCurrentPage(){
+// In this function we refresh the page currently loaded every DATA_REFRESH_RATE
+  if((millis() - pageRefreshTimer) > DATA_REFRESH_RATE){
+    switch(myNex.currentPageId){
+      case 0:
+        refreshPage0();
+        break;
+      
+      case 1:
+        refreshPage1();
+        break;
+        
+      case 2:
+        refreshPage2();
+        break;
+        
+      case 3:
+        refreshPage3();
+        break;
+     
+    }
+    pageRefreshTimer = millis();
+  }
+}
+
+void refreshPage0(){
+  // Use lastSentTemperature, in order to update the components ONLY when their value has changed 
+  // and avoid sending unnecessary data over Serial.
+  // Also with the newPageLoaded boolean variable, we bypass the if() argument of temperature != lastSentTemperature (last value comparison)
+  // so as to update all the values on Nextion when a new page is loaded, independant of if the values have changed
+  
+  if(temperature != lastSentTemperature || newPageLoaded == true){
+    
+    String tempString = String(temperature, 1); // Convert the float value to String, in order to send it to t0 textbox on Nextion
+    myNex.writeStr("t0.txt", tempString);       //Write the String value to t0 Textbox component
+    
+    int tempInt = temperature*10;    // We convert the float to int, in order to send it to x0 Xfloat component on Nextion
+                                     // We multiply it x10, because Xfloat will put a comma automatically after the last digit
+                                     // if vvs1 is set to 1
+    myNex.writeNum("x0.val", tempInt);
+    
+    lastSentTemperature = temperature;   // We store the last value that we have sent on Nextion, we wait for the next comparison 
+                                         // and send data only when the value of temperature changes
+  }
+}
+
+void refreshPage1(){
+  
+  if(humidity != lastSentHumidity || newPageLoaded == true){
+    
+    String tempString = String(humidity, 1);
+    myNex.writeStr("t0.txt", tempString);
+    
+    int tempInt = humidity*10;
+    myNex.writeNum("x0.val", tempInt);
+    
+    lastSentHumidity = humidity;
+  }
+}
+
+void refreshPage2(){
+
+  if(fahrenheit != lastSentFahrenheit || newPageLoaded == true){
+    
+    String tempString = String(fahrenheit, 1);
+    myNex.writeStr("t0.txt", tempString);
+    
+    int tempInt = fahrenheit*10;
+    myNex.writeNum("x0.val", tempInt);
+    
+    lastSentFahrenheit = fahrenheit;
+  }
+}
+
+void refreshPage3(){
+
+  if(heatIndexCelsius != lastSentHeatIndexCelsius || newPageLoaded == true){
+    
+    String tempString = String(heatIndexCelsius, 1);
+    myNex.writeStr("t0.txt", tempString);
+    
+    int tempInt = heatIndexCelsius*10;
+    myNex.writeNum("x0.val", tempInt);
+    
+    lastSentHeatIndexCelsius = heatIndexCelsius;
+  }
+  
+  if(heatIndexFahrenheit != lastSentHeatIndexFahrenheit || newPageLoaded == true){
+    String tempString = String(heatIndexFahrenheit, 1);
+    myNex.writeStr("t1.txt", tempString);
+    
+    int tempInt = heatIndexFahrenheit*10;
+    myNex.writeNum("x1.val", tempInt);
+    
+    lastSentHeatIndexFahrenheit = heatIndexFahrenheit;
+  }
+  
+}

BIN
examples/ExampleReadCustomCommand/easyNexReadCustomCommand.HMI


+ 198 - 0
examples/ExampleReadCustomCommand/easyNexReadCustomCommand/easyNexReadCustomCommand.ino

@@ -0,0 +1,198 @@
+/*
+ * easyNexReadCustomCommand.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+// Compatible for Arduino
+
+
+// As example we use 2 arrays (tables) of integers where we are going
+// to change their values with custom commands. 
+/*
+      The format is the known: # len cmd id id2
+
+  where the id referred to the position (element) of the array we want to write on
+  And id2 carries the value to write on the element of array
+  the custom command from Nextion: printh 23 03 4C 00 0A
+
+  4C is the Hex for letter L and we referred to the array dataL[]
+  00 Hex of Dec number 0 used as the index for each array element
+  0A Hex of Dec number 10 is the value we are going to write on element 0
+  After the command executed by our code, the values on dataL[] array will be
+
+  dataL[4] = {10,0,0,0}
+  Same for the dataS[] intead that cmd is the 53 Hex for letter S
+        Documentation to the end of the code
+
+*/
+ int dataL[4] = {0,0,0,0}; //values 0 or 1
+                          // printh 23 03 4C 00 00 
+ 
+ int dataS[4] = {0,0,0,0}; // values from 0 to 100
+                          // printh 23 03 53 00 00
+
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+ 
+  delay(500);               // give Nextion some time to finish initialize
+  myNex.writeStr("page 0"); // For synchronizing Nextion page in case of reset to Arduino
+  delay(50);
+  myNex.lastCurrentPageId = 1; // At the first run of the loop, the currentPageId and the lastCurrentPageId
+                               // must have different values, due to run the function firstRefresh()
+}
+
+void loop(){
+  myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+
+  firstRefresh(); 
+}
+
+void easyNexReadCustomCommand(){
+
+ int arrayPlace; // temp variable
+ int value;      // temp variable
+ String numericAttribute;
+
+ 
+  switch(myNex.cmdGroup){
+  
+    case 'L': // Or <case 0x4C:>  If 'L' matches
+      // we are going to write values in specific places in the dataL[] table
+      // read the next byte that determines the position on the table
+      arrayPlace = myNex.readByte();
+      
+      // read the next byte that keeps the value for the position
+      value = myNex.readByte();
+      
+      // update the array with the new values
+      dataL[arrayPlace] = value;
+      
+      // show the updated values of the array on Nextion to check them
+      // use this Line to update only the one that you have change
+      numericAttribute = "n"; numericAttribute += arrayPlace; numericAttribute += ".val";
+      myNex.writeNum(numericAttribute, dataL[arrayPlace]);
+       
+       // Uncomment this block to update all the values on Nextion
+       /*
+      myNex.writeNum("n0.val", dataL[0]);
+      myNex.writeNum("n1.val", dataL[1]);
+      myNex.writeNum("n2.val", dataL[2]);
+      myNex.writeNum("n3.val", dataL[3]); */
+      
+      break;
+    
+    case 'S': // Or <case 0x53:>  If 'S' matches 
+      //  ********* PAGE2 ON NEXTION ********
+      // we are going to write values in specific places in the dataS[] table
+      // from Nextion printh 23 03 53 00 and after that prints n0.val,1 in order to have one byte with the value of n0 attribute.
+      // The value of n0 can take values from 0 to 255 as it is only one byte
+      
+      // read the next byte that determines the position on the table
+      arrayPlace = myNex.readByte();
+      
+      // read the next byte that keeps the value for the position
+      value = myNex.readByte();
+      
+      // update the array with the new values
+      dataS[arrayPlace] = value;
+      
+      // show the updated values of the array on Nextion to check them
+      // use this Line to update only the one that you have change
+      numericAttribute = "n"; numericAttribute += (arrayPlace + 4); numericAttribute += ".val";
+      myNex.writeNum(numericAttribute, dataS[arrayPlace]);
+  /*     
+      myNex.writeNum("n4.val", dataS[0]);
+      myNex.writeNum("n5.val", dataS[1]);
+      myNex.writeNum("n6.val", dataS[2]);
+      myNex.writeNum("n7.val", dataS[3]);
+           */
+      
+      break;
+  }
+
+}
+
+void firstRefresh(){ // This function's purpose is to update the values of a new page when is first loaded,
+                     // and refreshing all the components with the current values as Nextion shows the Attribute val.
+
+  if(myNex.currentPageId != myNex.lastCurrentPageId){ // If the two variables are different, means a new page is loaded.
+
+    
+    switch(myNex.currentPageId){
+      case 0:
+        myNex.writeNum("n0.val", dataL[0]);
+        myNex.writeNum("n1.val", dataL[1]);
+        myNex.writeNum("n2.val", dataL[2]);
+        myNex.writeNum("n3.val", dataL[3]);  
+      break;
+      
+      case 1:
+        myNex.writeNum("n4.val", dataS[0]);
+        myNex.writeNum("n5.val", dataS[1]);
+        myNex.writeNum("n6.val", dataS[2]);
+        myNex.writeNum("n7.val", dataS[3]);
+        
+        myNex.writeNum("n0.val", dataS[0]);
+        myNex.writeNum("n1.val", dataS[1]);
+        myNex.writeNum("n2.val", dataS[2]);
+        myNex.writeNum("n3.val", dataS[3]);
+      break;
+
+    }
+
+    
+    myNex.lastCurrentPageId = myNex.currentPageId; // Afer the refresh of the new page We make them equal,
+                                                   // in order to identify the next page change.
+  }
+}
+
+            /*   More for custom protocol and commands https://seithan.com/Easy-Nextion-Library/Custom-Protocol/
+               
+      easyNexReadCustomCommand() has a weak attribute and will be created only when user
+      declare this function on the main code
+      More for custom protocol and commands https://seithan.com/Easy-Nextion-Library/Custom-Protocol/
+      our commands will have this format: <#> <len> <cmd> <id> <id2>
+      and we must send them from Nextion as HEX with the printh command
+      like: printh 23 03 4C 01 01
+
+      <#> start marker, declares that a command is followed
+      <len> declares the number of bytes that will follow
+      <cmd> declares the task of the command or command group
+      <id> declares the properties of the command
+      <id2> a second property of the command
+      
+      When we send a custom command with the above format, the function NextionListen() will capture the start marker # and the len (first 2 bytes)
+      and it will wait until all the bytes of the command, as we have declared with the len byte, arrive to the Serial buffer and inside the timeout limits.
+      
+      After that, the function will read the next byte, which is the command group and the function readCommand() takes over and through a switch command
+      tries to match the _cmd variable that holds the command group value with the statements of the cases.
+      
+      If we do NOT have a match with the predefined, cmd of P for page and T for triggers, it will continue to the default where we store the _cmd and _len to the public variables
+      cmdGroup and cmdLenght as we are going to need access to them from the main code in the next step.
+      
+      Next we call the the easyNexReadCustomCommand() with the precondition and ONLY if we have declared the function in the main code.
+      
+      From this point we can handle the assign of cmdGroup and IDs from the easyNexReadCustomCommand() in the user code, where we can go on with a switch case
+      for the cmdGroup, the one that we have stored the _cmd for public use and we can call it with myObject.cmdGroup. This is why we made cmdGroup a public variable.
+                     */

BIN
examples/FourStepExample/FourStepExample.HMI


+ 71 - 0
examples/FourStepExample/FourStepExampleCode/FourStepExampleCode.ino

@@ -0,0 +1,71 @@
+/*
+ * FourStepExample.ino - Simple example code
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >.
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ // https://www.seithan.com 
+ //********************************************************************************
+ 
+// Compatible for Arduino 
+
+/* This is the most important method of the library. 
+ * And this is because, it gives you the ability to use the predefined functions and run your code from there. 
+ * These predefined functions are named trigger0(), trigger1(), trigger2()... up to trigger50(). 
+ * You can use them as a simple void out of the loop, in which you will have written a block of code to run every time it is called.
+ * You can call those trigger() functions and run the code they contain anytime by simply writing in a Nextion Event the command:
+ * `printh 23 02 54 XX` , where `XX` the id for the triggerXX() in HEX.
+ * Example: printh 23 02 54 00 to call trigger0() ... printh 23 02 54 0A to call trigger10() and so on...
+ */
+
+/*
+  Declare the void by simply writing:
+  void trigger0(){
+  [ put your code here !!!!]
+  }
+*/
+ 
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex > 
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used 
+  pinMode(LED_BUILTIN, OUTPUT);   // The built-in LED is initialized as an output          
+  digitalWrite(LED_BUILTIN, LOW); // Setting the built-in LED to LOW = off
+}
+
+void loop(){
+  myNex.NextionListen(); // This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+}
+
+void trigger0(){
+  /* Create a button on Nextion
+   * Write in the Touch Release Event of the button
+   * this command:    printh 23 02 54 00
+   * Every time the button is pressed, the trigger0() function will run
+   * and the code inside will be executed once
+   */
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
+  if(digitalRead(LED_BUILTIN) == HIGH){
+    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
+    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
+    
+  }else if(digitalRead(LED_BUILTIN) == LOW){
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
+  }
+}

+ 71 - 0
examples/FourStepExample/FourStepExampleCodeWeMos/FourStepExampleCodeWeMos.ino

@@ -0,0 +1,71 @@
+/*
+ * FourStepExample.ino - Simple example code
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >.
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+// Compatible for WeMos D1 mini
+ 
+/* This is the most important method of the library. 
+ * And this is because, it gives you the ability to use the predefined functions and run your code from there. 
+ * These predefined functions are named trigger0(), trigger1(), trigger2()... up to trigger50(). 
+ * You can use them as a simple void out of the loop, in which you will have written a block of code to run every time it is called.
+ * You can call those trigger() functions and run the code they contain anytime by simply writing in a Nextion Event the command:
+ * `printh 23 02 54 XX` , where `XX` the id for the triggerXX() in HEX.
+ * Example: printh 23 02 54 00 to call trigger0() ... printh 23 02 54 0A to call trigger10() and so on...
+ */
+
+/*
+  Declare the void by simply writing:
+  void trigger0(){
+  [ put your code here !!!!]
+  }
+*/
+ 
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex > 
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used 
+  pinMode(LED_BUILTIN, OUTPUT);    // The built-in LED is initialized as an output            
+  digitalWrite(LED_BUILTIN, HIGH); // Setting the built-in LED to HIGH = off
+}
+
+void loop(){
+  myNex.NextionListen(); // This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+}
+
+void trigger0(){
+  /* Create a button on Nextion
+   * Write in the Touch Release Event of the button
+   * this command:    printh 23 02 54 00
+   * Every time the button is pressed, the trigger0() function will run
+   * and the code inside will be executed once
+   */
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
+  if(digitalRead(LED_BUILTIN) == LOW){
+    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
+    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
+    
+  }else if(digitalRead(LED_BUILTIN) == HIGH){
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
+  }
+}

BIN
examples/ReadAndWriteNumber/ReadAndWriteNumber.HMI


+ 73 - 0
examples/ReadAndWriteNumber/ReadAndWriteNumberCode/ReadAndWriteNumberCode.ino

@@ -0,0 +1,73 @@
+/*
+ * ReadAndWriteNumberCode.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >.
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ // https://www.seithan.com 
+ //********************************************************************************
+
+ // Compatible for Arduino and WeMos D1 mini ESP8266 
+ 
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary 
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+uint32_t number = 0;
+uint32_t lastnumber = 0;
+
+#define LOOP_TIME 2000
+unsigned long timer ;
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+  delay(500);        // Wait for Nextion to start
+  
+  timer = millis();
+}
+
+void loop(){
+
+  if((millis() - timer) > LOOP_TIME){
+    number = myNex.readNumber("n0.val");   // We read the value of n0 and store it to number variable
+    
+    if(number != 777777){                     // 777777 is the return value if the code fails to read the new value
+      lastnumber = number;                  // The chances of getting a wrong value is one in a million.
+                                            // Use this if() to ensure it if you believe it is needed.    
+                                            // You can either call the readNumber funtion again 
+                                            // or set a safe value in case of failure.
+                                            // Ex: number = 2222; or use the last value method
+    } else if(number == 777777){
+      number = lastnumber;
+    }
+    
+    myNex.writeNum("n1.val", number);       // After that, we send the number variable, as value to n1
+    
+    number = myNex.readNumber("page0.bco"); // Read and store the background color code to number variable
+    if(number == 33823){
+      myNex.writeNum("page0.bco", 63488);   // Change background color to RED(63488) if it was BLUE(33823)
+    }else if(number == 63488){
+      myNex.writeNum("page0.bco", 33823);   // Change background color to BLUE(33823) if it was RED(63488)
+    }
+                  // As these commands are using Serial to read and write, 
+                  // it is more preferred not to run them in the loop() without delay(); 
+                  // or some other method of not running them with the frequency of the loop
+                  // and use them only when it is needed.
+                  // A delay in the loop can be noticed, especially when reading from Serial
+                  // And of course to avoid a Serial buffer overflow
+  
+    timer = millis();
+               
+  }
+}

+ 61 - 0
examples/ReadString/ReadFromStringExample/ReadFromStringExample.ino

@@ -0,0 +1,61 @@
+/*
+ * ReadFromStringExample.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+ /* This example aims to show how you can use the readStr() function of the Library
+  * With this Function you can read a string component from Nextion
+  */
+ 
+ #include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+                                 // Download the latest version https://github.com/Seithan/EasyNextionLibrary
+                                 // or from Arduino's IDE Library Manager
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+
+const int REFRESH_TIME = 1000;           // time to refresh the Nextion data every 1000 ms
+unsigned long refresh_timer = millis();  // timer for refreshing Nextion's page
+                 
+String stringFromNextion;
+
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+  
+}
+
+void loop(){
+  myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+                         
+ if((millis() - refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
+                                                // or an if statement with a timer condition like this one.
+                                              
+    stringFromNextion = myNex.readStr("t0.txt");
+    myNex.writeStr("t1.txt",stringFromNextion);
+    
+      refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
+     
+    }                          
+                         
+}
+
+
+
+

BIN
examples/ReadString/readStr.HMI


BIN
examples/Trigger/Trigger.HMI


+ 101 - 0
examples/Trigger/TriggerCode/TriggerCode.ino

@@ -0,0 +1,101 @@
+/*
+ * TriggerCode.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+// Compatible for Arduino
+
+/* This is the most important method of the library. 
+ * And this is because, it gives you the ability to use the predefined functions and run your code from there. 
+ * These predefined functions are named trigger0(), trigger1(), trigger2()... up to trigger50(). 
+ * You can use them as a simple void out of the loop, in which you will have written a block of code to run every time it is called.
+ * You can call those trigger() functions and run the code they contain anytime by simply writing in a Nextion Event the command:
+ * `printh 23 02 54 XX` , where `XX` the id for the triggerXX() in HEX.
+ * Example: printh 23 02 54 00 to call trigger0() ... printh 23 02 54 0A to call trigger10() and so on...
+ */
+
+/*
+  Declare the void by simply writing:
+  void trigger0(){
+  [ put your code here !!!!]
+  }
+*/
+
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+  
+  pinMode(LED_BUILTIN, OUTPUT); // The built-in LED is initialized as an output
+  digitalWrite(LED_BUILTIN, LOW);
+}
+
+void loop(){
+  myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+}
+
+void trigger0(){
+  // To call this void send from Nextion's component's Event:  printh 23 02 54 00
+  // In this exmaple, we send this command from the Release Event of b0 button (see the HMI of this example)
+  // You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
+
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
+  if(digitalRead(LED_BUILTIN) == HIGH){
+    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
+    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
+    myNex.writeNum("p0.pic", 1);    // Set picture 1 as background picture for p0
+    
+  }else if(digitalRead(LED_BUILTIN) == LOW){
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "OFF"
+    myNex.writeNum("p0.pic", 0);     // Set picture 0 as background picture for p0 picture component
+  }
+}
+
+void trigger1(){
+  // To call this void send from Nextion's component's Event:  printh 23 02 54 01
+  // In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
+  // You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
+  
+  if(digitalRead(LED_BUILTIN) == HIGH){
+    digitalWrite(LED_BUILTIN, LOW);  // Start the function with the LED off
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "OFF"
+    myNex.writeNum("p0.pic", 0);     // Set picture 0 as background picture for p0 picture component
+  }
+  
+  myNex.writeStr("t0.txt", "LED STROBE\\rON");
+  for(int i = 0; i < 10; i++){
+    for(int x = 0; x < 10; x++){
+      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
+      delay(50);
+    }
+    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));   // If LED_BUILTIN is ON, turn it OFF, or the opposite
+    delay(500);
+    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));   // If LED_BUILTIN is ON, turn it OFF, or the opposite
+  }
+  myNex.writeStr("t0.txt", "LED STROBE\\rOFF"); // Setting the text of t0 textbox to "LED STROBE OFF"
+                                                // \\r is the newline character for Nextion.
+                                                // The text will look like this:
+                                                // 1st line: LED STROBE
+                                                // 2nd line: OFF                                                
+}

+ 100 - 0
examples/Trigger/TriggerCodeWeMos/TriggerCodeWeMos.ino

@@ -0,0 +1,100 @@
+/*
+ * TriggerCodeWemos.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+/* This is the most important method of the library. 
+ * And this is because, it gives you the ability to use the predefined functions and run your code from there. 
+ * These predefined functions are named trigger0(), trigger1(), trigger2()... up to trigger50(). 
+ * You can use them as a simple void out of the loop, in which you will have written a block of code to run every time it is called.
+ * You can call those trigger() functions and run the code they contain anytime by simply writing in a Nextion Event the command:
+ * `printh 23 02 54 XX` , where `XX` the id for the triggerXX() in HEX.
+ * Example: printh 23 02 54 00 to call trigger0() ... printh 23 02 54 0A to call trigger10() and so on...
+ */
+
+/*
+  Declare the void by simply writing:
+  void trigger0(){
+  [ put your code here !!!!]
+  }
+*/
+
+
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                     // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+  
+  pinMode(LED_BUILTIN, OUTPUT); // The built-in LED is initialized as an output
+  digitalWrite(LED_BUILTIN, HIGH);
+}
+
+void loop(){
+  myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
+                         // from Nextion touch panel. Actually, you should place it in your loop function.
+}
+
+void trigger0(){
+  // To call this void send from Nextion's component's Event:  printh 23 02 54 00
+  // In this exmaple, we send this command from the Release Event of b0 button (see the HMI of this example)
+  // You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
+
+  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
+  if(digitalRead(LED_BUILTIN) == LOW){
+    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
+    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
+    myNex.writeNum("p0.pic", 1);    // Set picture 1 as background picture for p0
+    
+  }else if(digitalRead(LED_BUILTIN) == HIGH){
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "OFF"
+    myNex.writeNum("p0.pic", 0);     // Set picture 0 as background picture for p0 picture component
+  }
+}
+
+void trigger1(){
+  // To call this void send from Nextion's component's Event:  printh 23 02 54 01
+  // In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
+  // You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
+  
+  if(digitalRead(LED_BUILTIN) == LOW){
+    digitalWrite(LED_BUILTIN, HIGH);  // Start the function with the LED off
+    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
+    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "OFF"
+    myNex.writeNum("p0.pic", 0);     // Set picture 0 as background picture for p0 picture component
+  }
+  
+  myNex.writeStr("t0.txt", "LED STROBE\\rON");
+  for(int i = 0; i < 10; i++){
+    for(int x = 0; x < 10; x++){
+      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
+      delay(50);
+    }
+    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));   // If LED_BUILTIN is ON, turn it OFF, or the opposite
+    delay(500);
+    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));   // If LED_BUILTIN is ON, turn it OFF, or the opposite
+  }
+  myNex.writeStr("t0.txt", "LED STROBE\\rOFF"); // Setting the text of t0 textbox to "LED STROBE OFF"
+                                                // \\r is the newline character for Nextion.
+                                                // The text will look like this:
+                                                // 1st line: LED STROBE
+                                                // 2nd line: OFF                                                
+}

BIN
examples/WriteTextAndCommands/WriteTextAndCommands.HMI


+ 95 - 0
examples/WriteTextAndCommands/WriteTextAndCommandsCode/WriteTextAndCommandsCode.ino

@@ -0,0 +1,95 @@
+/*
+ * WriteTextAndCommands.ino - Simple example code for EasyNextionLibrary
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * https://www.seithan.com 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */
+ 
+/* I have invested time and resources providing open source codes, like this one. 
+ * Please do not hesitate to support my work!
+ * If you found  this work useful and has saved you time and effort,
+ * Just simply paypal me at: seithagta@gmail.com
+ */
+ 
+ //********************************************************************************
+ //  You can find more examples, tutorials and projects with Nextion on my website
+ //  https://www.seithan.com 
+ //********************************************************************************
+ 
+#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
+
+EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex >
+                       // Set as parameter the Hardware Serial you are going to use
+
+void setup(){
+  myNex.begin(9600); // Begin the object with a baud rate of 9600
+                       // If no parameter was given in the begin(), the default baud rate of 9600 will be used
+}
+
+void loop(){
+  /* Use writeStr(String) for sending commands. 
+   * Use ONLY the first parameter
+   * In the first parameter, write the command according to the instructions of Nextion's Instruction Set 
+   * Do NOT write ANYTHING in the second parameter. Leave it empty.
+   * TIP: Write in the debug mode the command to check if it is written correctly
+   * example: The command to change the page and go to page0, is:  page page0(page0 is the name of the page) 
+   * or page 0(0 is the ID of the page)
+   */
+  myNex.writeStr("page page0"); // Sending this command to change the page we are on Nextion using pageName
+  delay(50); // Some time for Nextion to execute the command
+  /* Use writeStr(String, String) to change the text in a textbox  
+   * Use BOTH parameters
+   * In the first parameter, write the objectName.textAttribute example: t0.txt or b0.txt
+   * In the second parameter, write the text you want to "print"
+   * Any previous text on the textbox is deleted
+   */
+  myNex.writeStr("t0.txt", "You are now transferred to page0"); // The text in t0 is now this
+  delay(2950);
+
+  
+  myNex.writeStr("page 1"); // Sending this command to change the page we are on Nextion using pageId
+  delay(50); // Some time for Nextion to execute the command
+  /* By writing \\r, you send Nextion the change line character < \r >
+   * The second \ is required, in order to print the \ as character
+   * and not as an escape character.
+   */
+  myNex.writeStr("t0.txt", "You are now transferred to page1\\r");
+  // Avoid using very big text Strings in the same command, as Nextion will not recognise them.
+  // Istead use a second command and in order to add to the existing text, use the + symbol, after the .textAttribute("t0.txt+").
+  myNex.writeStr("t0.txt+", "This is the:\\rWriteTextAndCommands example");
+  myNex.writeStr("t0.txt+", "\\rEvery 3000ms we change page");
+  myNex.writeStr("t0.txt+", "\\rAnd we print a text to t0");
+  delay(4950);
+  
+  myNex.writeStr("page page2");
+  delay(50); // Some time for Nextion to execute the command
+  myNex.writeStr("t0.txt", "You are now transferred to page2\\r");
+  myNex.writeStr("t0.txt+", "Thank you\\rfor choosing my library!!!");
+  myNex.writeStr("t0.txt+", "\\rEnjoy the library!!!");
+  myNex.writeStr("t0.txt+", "\\r\\rAthanasios Seitanis");
+  myNex.writeStr("t0.txt+", "\\rseithagta@gmail.com");
+  delay(7950);
+  
+  myNex.writeStr("t0.txt", "Screen will go to sleep mode in");
+  myNex.writeStr("t0.txt+", "\\r3...");
+  delay(1000);
+  myNex.writeStr("t0.txt+", "2...");
+  delay(1000);
+  myNex.writeStr("t0.txt+", "1...");
+  delay(1000);
+  myNex.writeStr("t0.txt", "S L E E P\\rSee you in 10 seconds!!!");
+  delay(1000);
+  
+  myNex.writeStr("sleep=1"); // Screen goes to sleep mode
+  delay(10000);
+  myNex.writeStr("sleep=0"); // Screen exits sleep mode
+  delay(100); // Give some time to Nextion to Exit sleep mode
+  
+  // As these commands are using Serial to read and write, 
+  // it is more preferred not to run them in the loop() without delay(); 
+  // or some other method of not running them with the frequency of the loop
+  // and use them only when it is needed.
+  // A delay in the loop can be noticed, especially when reading from Serial
+  // And of course to avoid a Serial buffer overflow
+}

+ 891 - 0
extras/README.html

@@ -0,0 +1,891 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>READMEV1</title>
+  <link rel="stylesheet" href="https://stackedit.io/style.css" />
+</head>
+
+<body class="stackedit">
+  <div class="stackedit__html"><h1 id="easy-nextion-library">Easy Nextion Library</h1>
+<h2 id="description">Description</h2>
+<p>A simple library that uses only four functions. You can easily benefit from Nextion’s wide range of features and advantages in just a few easy steps.<br>
+The library uses a custom protocol that can prove to be a <strong>powerful tool</strong> for advanced users as it can be <strong>easily modified</strong> to meet one’s needs.<br>
+This is an attempt to give a very simple method to use Nextion monitors for beginners at programming and at the same time to be a strong and reliable method that can be capable of satisfying the needs of the advance programming.<br>
+The handling of Nextion should be as simple and at the same time as professional as a display of this kind deserves.</p>
+<p>I have invested time and resources providing open source codes, like this one. Please do not hesitate to support my work!<br>
+If you found this work useful and has saved you time and effort,<br>
+just simply paypal me at this Link: <a href="https://paypal.me/seithan">seithagta@gmail.com</a></p>
+<p>You can find more examples, tutorials and projects with Nextion on my website <a href="https://seithan.com/">seithan.com</a> or at my YouTube channel <a href="https://www.youtube.com/channel/UCk_AjYtvzUC58ups5Lm053g">Thanasis Seitanis</a></p>
+<h2 id="installation">Installation</h2>
+<h3 id="first-method">First Method</h3>
+<ol>
+<li>In the Arduino IDE, navigate to Sketch &gt; Include Library &gt; Manage Libraries</li>
+<li>Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.</li>
+<li>Then search for EasyNextionLibrary using the search bar.</li>
+<li>Click on the text area and then select the latest version and install it.</li>
+</ol>
+<p><img src="../media/EasyNextionLibrary_Arduino_Library_Manager.png" alt="enter image description here"></p>
+<h3 id="second-method">Second Method</h3>
+<ol>
+<li>Download the latest release of EasyNextionLibrary.</li>
+</ol>
+<ul>
+<li>From: <a href="https://github.com/Seithan/EasyNextionLibrary">https://github.com/Seithan/EasyNextionLibrary</a></li>
+</ul>
+<ol start="2">
+<li>Extract the <code>.zip</code> file</li>
+<li>Copy the EasyNextionLibrary folder, to: …\Arduino\libraries\</li>
+</ol>
+<p><em><strong>NOTE</strong></em>: <code>.HMI</code> files for Nextion Editor are also included in every example’s folder.<br>
+All <code>.HMIs</code> are set for 2.8" Basic screens, so as to be easier to modify it for bigger screens.</p>
+<h2 id="the-main-functions">The main functions</h2>
+<ul>
+<li><code>begin();</code></li>
+<li><code>writeNum();</code></li>
+<li><code>writeStr();</code></li>
+<li><code>readNumber();</code></li>
+<li><code>trigger();</code></li>
+<li><code>readStr();</code> Added with version 1.0.4</li>
+</ul>
+<p><em><strong>And the public variables:</strong></em></p>
+<ul>
+<li>currentPageId (Data Type: <strong>Integer</strong>)</li>
+<li>lastCurrentPageId (Data Type: <strong>Integer</strong>)</li>
+</ul>
+<p><strong>Functions for user custom command protocol</strong></p>
+<ul>
+<li><code>readByte();</code> Added with version 1.0.5</li>
+<li><code>easyNexReadCustomCommand()</code> Added with version 1.0.5<br>
+and the public variables for user custom command protocol Added with version 1.0.5</li>
+<li><code>cmdGroup</code> (Data Type: <strong>Byte</strong>)</li>
+<li><code>cmdLength</code> (Data Type: <strong>Byte</strong>)</li>
+</ul>
+<h3 id="details-examples-and-explanation-on-custom-protocol-can-be-found-on-my-website-at">Details, examples and explanation on custom protocol, can be found on my website at:</h3>
+<h4 id="httpsseithan.comeasy-nextion-librarycustom-protocol"><a href="https://seithan.com/Easy-Nextion-Library/Custom-Protocol/">https://seithan.com/Easy-Nextion-Library/Custom-Protocol/</a></h4>
+<h2 id="step-example">4-step Example</h2>
+<ol>
+<li><strong>Include</strong> <em><strong>EasyNextionLibrary</strong></em> and create an object of <code>EasyNex</code> class</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"EasyNextionLibrary.h"</span>  </span><span class="token comment">// Include EasyNextionLibrary</span>
+
+EasyNex <span class="token function">myNex</span><span class="token punctuation">(</span>Serial<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Create an object of EasyNex class with the name &lt; myNex &gt; </span>
+                       <span class="token comment">// Set as parameter the Hardware Serial you are going to use</span>
+</code></pre>
+<ol start="2">
+<li><strong>Begin the object</strong> and give the desired baud rate as a parameter. Also, initialize the built-in LED as output</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">9600</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Begin the object with a baud rate of 9600</span>
+                     <span class="token comment">// If no parameter was given in the begin(), the default baud rate of 9600 will be used </span>
+  <span class="token function">pinMode</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> OUTPUT<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// The built-in LED is initialized as an output                     </span>
+<span class="token punctuation">}</span>
+</code></pre>
+<ol start="3">
+<li><strong>Place</strong> the <strong>NextionListen()</strong> function in the loop.</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">NextionListen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// This function must be called repeatedly to response touch events</span>
+                         <span class="token comment">// from Nextion touch panel. Actually, you should place it in your loop function.</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<ol start="4">
+<li><strong>Select one of the 50 predefined trigger()</strong> functions and use it as a simple void function (nothing returned).<br>
+Declare the void function by simply writing:</li>
+</ol>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+<span class="token punctuation">[</span> put your code here <span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">]</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<ul>
+<li>Write the code you want to run in there.<br>
+The <code>trigger0()</code> function will run every time the following sequence of bytes (in HEX format) <code>23 02 54 00</code> comes to Arduino’s Serial. To do that, write in the <code>Touch Release Event</code> of the button b0, this command: <code>printh 23 02 54 00</code></li>
+</ul>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+
+  <span class="token function">digitalWrite</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> <span class="token operator">!</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
+  <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> HIGH<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">2016</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to GREEN (color code: 2016)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"ON"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+    
+  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> LOW<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">63488</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to RED (color code: 63488)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"OFF"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+  <span class="token punctuation">}</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p>Enjoy the Easy Nextion Library!! Please do not forget the LED on :)</p>
+<h2 id="full-example-code">Full Example Code</h2>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token comment">/*
+ * FourStepExample.ino - Simple example code
+ * Copyright (c) 2020 Athanasios Seitanis &lt; seithagta@gmail.com &gt;. 
+ * All rights reserved. EasyNextionLibrary is licensed under the MIT License
+ * https://opensource.org/licenses/MIT
+ */</span>
+<span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"EasyNextionLibrary.h"</span>  </span><span class="token comment">// Include EasyNextionLibrary</span>
+
+EasyNex <span class="token function">myNex</span><span class="token punctuation">(</span>Serial<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Create an object of EasyNex class with the name &lt; myNex &gt; </span>
+                       <span class="token comment">// Set as parameter the Hardware Serial you are going to use</span>
+
+<span class="token keyword">void</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">9600</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Begin the object with a baud rate of 9600</span>
+                     <span class="token comment">// If no parameter was given in the begin(), the default baud rate of 9600 will be used </span>
+                     
+  <span class="token function">pinMode</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> OUTPUT<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// The built-in LED is initialized as an output                     </span>
+<span class="token punctuation">}</span>
+
+<span class="token keyword">void</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myNex<span class="token punctuation">.</span><span class="token function">NextionListen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// This function must be called repeatedly to response touch events</span>
+                         <span class="token comment">// from Nextion touch panel. Actually, you should place it in your loop function.</span>
+<span class="token punctuation">}</span>
+
+<span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  <span class="token comment">/* Create a button on Nextion
+   * Write in the Touch Release Event of the button
+   * this command:    printh 23 02 54 00
+   * Every time the button is pressed, the trigger0() function will run
+   * and the code inside will be executed once
+   */</span>
+  <span class="token function">digitalWrite</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> <span class="token operator">!</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//If LED_BUILTIN is ON, turn it OFF, or the opposite</span>
+  <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> HIGH<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">2016</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to GREEN (color code: 2016)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"ON"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+    
+  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span> <span class="token operator">==</span> LOW<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">,</span> <span class="token number">63488</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 background color to RED (color code: 63488)</span>
+    myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"b0.txt"</span><span class="token punctuation">,</span> <span class="token string">"OFF"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set button b0 text to "ON"</span>
+  <span class="token punctuation">}</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<h2 id="function-documentation">Function documentation</h2>
+<p><em><strong>The various combinations of attribute choices provide a wide range of expected behaviors with many combinations.<br>
+This combined with the Nextion Instruction Set creates the opportunity for very powerful HMIs.</strong></em></p>
+<p><em><strong>NOTE</strong></em>:<br>
+As these commands are using the Serial port to read and write, it is more preferred not to run them in the loop() without delay(); or some other method of not running them with the frequency of the loop and use them only when it is needed.<br>
+Using them in a loop, a delay in the loop can be noticed, especially when reading from the Serial. A Serial buffer overflow can also be caused.<br>
+<em><strong>Also NOTE</strong></em>: (from the Nextion Editor Guide)</p>
+<blockquote>
+<p>In an HMI project a page is a localized unit. When changing pages, the existing page is removed from memory and the &gt; &gt; requested page is then loaded into memory. As such components with a variable scope of <em><strong>local</strong></em> are only accessible while the page they are in is currently loaded. Components within a page that have a variable scope of <em><strong>global</strong></em> are accessible by prefixing the page name to the global component .objname.<br>
+As an Example:<br>
+A global Number component n0 on page1 is accessed by <strong>page1.n0</strong> .<br>
+A local Number component n0 on page1 can be accessed by page1.n0 or n0, but there is little sense to try access a local component if the page is not loaded. Only the component attributes of a global component are kept in memory. Event code is never global in nature.</p>
+</blockquote>
+<h3 id="function-trigger">Function trigger();</h3>
+<p><strong><code>Associated Library's Code Example:</code></strong> <strong><em><code>Trigger</code></em> <strong><code>and</code></strong> <em><code>FourStepExample</code></em></strong></p>
+<p><em><strong>Description:</strong></em><br>
+This is the most important function of the library.<br>
+And this is because, it gives you the ability to use the predefined functions and run your code from there.<br>
+These predefined functions are named <code>trigger0()</code>, <code>trigger1()</code>, <code>trigger2()</code>… up to <code>trigger50()</code>.<br>
+You can use them as a simple void function out of the loop, in which you will have written a block of code to run every time it is called.<br>
+You can call those <code>trigger()</code> functions and run the code they contain anytime by simply writing in a Nextion Event the command: <code>printh 23 02 54 XX</code> , where <code>XX</code> the id for the triggerXX() in HEX.<br>
+For example in a button’s Touch Release Event, write:</p>
+
+<table>
+<thead>
+<tr>
+<th>Command</th>
+<th>Function</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>printh 23 02 54 00</td>
+<td>trigger0()</td>
+</tr>
+<tr>
+<td>printh 23 02 54 01</td>
+<td>trigger1()</td>
+</tr>
+<tr>
+<td>…</td>
+<td>…</td>
+</tr>
+<tr>
+<td>printh 23 02 54 0A</td>
+<td>trigger10()</td>
+</tr>
+<tr>
+<td>… up to</td>
+<td>… up to</td>
+</tr>
+<tr>
+<td>printh 23 02 54 32</td>
+<td>trigger50()</td>
+</tr>
+</tbody>
+</table><p>In Arduino code, declare a void <code>trigger()</code> function with the predefined name you want to use and put your code there.<br>
+Declare the void function by simply writing:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+<span class="token punctuation">[</span> put your code here <span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">]</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p>Example:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"EasyNextionLibrary.h"</span></span>
+
+EasyNex <span class="token function">myObject</span><span class="token punctuation">(</span>Serial<span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token keyword">void</span> <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">9600</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+  <span class="token function">pinMode</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> OUTPUT<span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+<span class="token keyword">void</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">NextionListen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+<span class="token keyword">void</span> <span class="token function">trigger0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  <span class="token function">digitalWrite</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">,</span> <span class="token operator">!</span><span class="token function">digitalRead</span><span class="token punctuation">(</span>LED_BUILTIN<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>1st NOTE</strong></em>: To change the predefined names of the <code>trigger()</code> functions, there are details inside the <code>trigger.cpp</code> file and you can add up to <strong>255</strong> functions of this kind.<br>
+<em><strong>2nd NOTE</strong></em>: You can send  the same <code>printh</code> command, to call the same function, from more than one component from any page, depending on your needs</p>
+<p><em>See Appendix at the end of the document for numbers in HEX table</em></p>
+<h3 id="function-begin">Function begin();</h3>
+<p><em><strong>Parameters:</strong></em><br>
+begin(<code>unsigned long</code>)<br>
+<strong>unsigned long</strong>: unsigned long baud = <strong>9600</strong> (default) if nothing is written in the begin() function</p>
+<p><em><strong>Description:</strong></em><br>
+<strong>The begin()</strong> method of the class in which we pass the initialization data to the objects.</p>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token number">115200</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// for baud rate 115200</span>
+</code></pre>
+<h3 id="function-writenum">Function writeNum();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ReadAndWriteNumber</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em><br>
+writeNum(<code>String</code>, <code>uint32_t</code>)</p>
+<ul>
+<li><strong>String</strong> = objectname.numericAttribute (example: “n0.val”  or “n0.bco”…etc)</li>
+<li><strong>uint32_t</strong> = value (example: 84)(number from 0 to 4,294,967,295)</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+For writing numbers in numeric attributes in components of any kind (variables, textboxes,  etc.).</p>
+<ul>
+<li>We can change the shown value of a number box</li>
+<li>We can change the value of a numeric attribute of the design editing commands. Those commands are used to change the attribute of the components (button, text box, timer, numeric etc.) while Nextion is running.</li>
+</ul>
+
+<table>
+<thead>
+<tr>
+<th>Command</th>
+<th>Result on n0 comp.</th>
+<th>Syntax</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>n0.val=30</td>
+<td>Sets n0 component’s shown value to 30</td>
+<td><code>myObject.writeNum("n0.val", 30);</code></td>
+</tr>
+<tr>
+<td>va0.val=30</td>
+<td>Sets va0 variable’s value to 30</td>
+<td><code>myObject.writeNum("va0.val", 30);</code></td>
+</tr>
+<tr>
+<td>n0.bco=63488</td>
+<td>Sets background color to red</td>
+<td><code>myObject.writeNum("n0.bco", 63488);</code></td>
+</tr>
+<tr>
+<td>n0.font=0</td>
+<td>Sets font to font style with Id = 0</td>
+<td><code>myObject.writeNum("n0.font", 0);</code></td>
+</tr>
+<tr>
+<td>n0.pco=1055</td>
+<td>Sets font color to blue</td>
+<td><code>myObject.writeNum("n0.pco", 1055);</code></td>
+</tr>
+<tr>
+<td>n0.format=0</td>
+<td>Sets value format to decimal</td>
+<td><code>myObject.writeNum("n0.format", 0);</code></td>
+</tr>
+</tbody>
+</table><p>With the same way you can change the xcen, ycen, length and isbr</p>
+<p><em><strong>TIP:</strong> In a timer component, at the attribute &lt; <strong>en</strong> &gt;, you can start or stop the timer by writing <strong>0</strong> or <strong>1</strong>.</em><br>
+Also, at the attribute &lt; <strong>tim</strong> &gt;, you can set the time the timer is going to repeat the commands written in timer’s User-code event.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"tm0.en"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">// 0 = stop, 1 = start</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"tm0.tim"</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// repeat code every 1000ms</span>
+</code></pre>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.val"</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// Set the value of numeric n0 to 30</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.bco"</span><span class="token punctuation">,</span> <span class="token number">63488</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set background color of n0 to 63488(red)</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.font"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// Set font to font style with ID 0</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.pco"</span><span class="token punctuation">,</span> <span class="token number">1055</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Set font color to blue</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"n0.format"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Set value format to decimal</span>
+</code></pre>
+<p><em><strong>NOTE:</strong> Only attributes shown in green in the Editor can be both read and changed by user code at runtime.</em><br>
+<img src="../media/AttributePane.png" alt="Attribute panel"></p>
+<h3 id="send-floating-point-numbers-a-number-that-has-a-decimal-point.">Send floating-point numbers, a number that has a decimal point.</h3>
+<h3 id="or-send-a-number-on-a-textbox">Or send a number on a textbox</h3>
+<p><em><strong>Description:</strong></em><br>
+Nextion <strong>DOES NOT SUPPORT</strong> float numbers. Instead, it uses integer math and does not have real or floating support.<br>
+The Xfloat component is used for signed 32-bit integer values.<br>
+The <code>.vvs0</code> sets the number of digits shown to the left of the decimal (useful for leading zeros).<br>
+The <code>.vvs1</code> sets the number of digits shown to the right of the decimal.</p>
+<p><em><strong>You can send Floating-point numbers with these two ways</strong></em>:</p>
+<ul>
+<li>On a <strong>Xfloat component</strong> after you convert the float to int and multiply it by 10, the Xfloat component will put a comma <code>,</code> (decimal point) automatically after the last digit  if attribute <code>vvs1</code> is set to 1.</li>
+</ul>
+<p><em><strong>Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">int</span> tempInt <span class="token operator">=</span> temperature<span class="token operator">*</span><span class="token number">10</span><span class="token punctuation">;</span>      <span class="token comment">// Convert the float to int. Multiply it x10                       </span>
+myNex<span class="token punctuation">.</span><span class="token function">writeNum</span><span class="token punctuation">(</span><span class="token string">"x0.val"</span><span class="token punctuation">,</span> tempInt<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Write it to x0 Xfloat component on Nextion</span>
+</code></pre>
+<p>it is obvious that if you want 2 decimal places, you will set the attribute <code>vvs1</code> to <code>2</code> and you will multiply by <code>100</code></p>
+<ul>
+<li>On a <strong>Textbox component</strong> after you convert the float value to String</li>
+</ul>
+<p><em><strong>Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">String tempString <span class="token operator">=</span> <span class="token function">String</span><span class="token punctuation">(</span>temperature<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Convert the float value to String, with 1 decimal place</span>
+myNex<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> tempString<span class="token punctuation">)</span><span class="token punctuation">;</span>       <span class="token comment">// Write the String value to t0 Textbox component</span>
+</code></pre>
+<h3 id="function-writestr">Function writeStr();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>WriteTextAndCommands</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em></p>
+<ul>
+<li>
+<p>writeStr(<code>String</code>, <code>String</code>). <em>To change the <code>.txt</code> attribute in components</em><br>
+<strong>String No1</strong>: objectname.textAttribute (example: “t0.txt”  or “b0.txt”)<br>
+<strong>String No2</strong>: value (example: “Hello World”)</p>
+</li>
+<li>
+<p>writeStr(<code>String</code>). <em>To send Designing and System Commands</em><br>
+<strong>String</strong>: The command to send on Nextion</p>
+</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+For writing text in Nextion. The two ways the command can be used:</p>
+<p><strong>First Usage of the command</strong>:<br>
+Use <strong>writeStr(</strong> <code>String</code>, <code>String</code> <strong>)</strong> to change the text in a textbox<br>
+Use both parameters to write text in textboxes.</p>
+<ul>
+<li>In the first parameter, write the objectName.textAttribute example: t0.txt or b0.txt</li>
+<li>In the second parameter, write the text you want to “print”</li>
+</ul>
+<p><em><strong>1st Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"Hello World"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Change t0 text to "Hello World"</span>
+</code></pre>
+<p>Any previous text on the textbox is deleted</p>
+<p>Avoid using very big text Strings in the same command, as Nextion will not recognise them. Istead use a second command and in order to add to the existing text, use the <strong><code>+</code></strong> symbol, after the <code>.textAttribute("t0.txt+")</code>.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"You are now transferred to page2\\rThank you\\rfor choosing my library!!!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt+"</span><span class="token punctuation">,</span> <span class="token string">"\\rEnjoy the library!!!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt+"</span><span class="token punctuation">,</span> <span class="token string">"\\r\\rAthanasios Seitanis\\rseithagta@gmail.com"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+  <span class="token comment">/* By writing \\r, you send Nextion the change line character &lt; \r &gt;
+   * The second \ is required, in order to print the \ as character
+   * and not as an escape character.
+   */</span>
+</code></pre>
+<p><strong>Second Usage of the command</strong>:<br>
+Use <strong>writeStr(</strong> <code>String</code> <strong>)</strong> to send Designing and System Commands according to the instructions of Nextion’s Instruction Set.<br>
+Use only the first parameter to send a command to Nextion. The commands must be syntaxed according to Nextion’s Instruction Set.</p>
+<p><em><strong>2nd Syntax:</strong></em><br>
+<em><strong>Design Commands Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"page page0"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Sending this command to change the page we are on Nextion using pageName</span>
+myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"page 1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Sending this command to change the page we are on Nextion using pageId</span>
+</code></pre>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"cir 100,100,30,RED"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Renders a hollow Red circle with circle center at (100,100)</span>
+</code></pre>
+<p><em><strong>System Commands Example:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"dim=50"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Set the current brightness level to 50%</span>
+</code></pre>
+<pre class=" language-cpp"><code class="prism  language-cpp">myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"sleep=1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// sleep=1 (Enter sleep mode) or sleep=0 (Exit sleep mode)</span>
+</code></pre>
+<p><em><strong>NOTE</strong>: When you decide to exit the sleep mode on Nextion, use a small delay of 50ms, in order to give Nextion some time to Exit sleep mode.</em><br>
+<em><strong>WARNING</strong>: DO NOT send commands that causes data return over Serial to MCU, unless you know what you are doing.</em><br>
+Commands that cause data return over serial:<br>
+<code>print</code>, <code>prints</code>, <code>printh</code>, <code>sendme</code>, <code>get</code>, <code>rept</code>, <code>rdfile</code>, <code>twfile</code><br>
+<em><strong>TIP</strong>: Write in the debug mode the command to check if it is written correctly</em></p>
+<h3 id="function-readnumber">Function readNumber();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ReadAndWriteNumber</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em><br>
+readNumber(<code>String</code>)</p>
+<ul>
+<li><strong>String</strong>: objectname.numericAttribute (example: “va0.val” “n0.val”, “n0.pco”, “n0.bco”…etc)</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+We use it to read the value of every components’ numeric attribute from Nextion (value, bco color, pco color…etc)</p>
+<p>In case the function fails to read the new value, it will return the number <code>777777</code>.<br>
+The reasons of getting <code>777777</code>: (from release 1.0.2 and above)</p>
+<ul>
+<li>Waiting bytes have not come to Serial timeout</li>
+<li>Command start character is not found in Serial timeout</li>
+<li>The waiting length of the byte package has not come to Serial</li>
+<li>Bytes on Serial are not the expected<br>
+The chances of getting a wrong value is one in a million.<br>
+You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value.<br>
+You can check it with an <strong><code>if()</code></strong> statement, in which you will ignore the value of <code>777777</code> and you can run the <code>readNumber()</code> again or set a safe value or use the last good known value method.</li>
+</ul>
+<pre class=" language-cpp"><code class="prism  language-cpp">uint32_t number <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
+uint32_t lastnumber <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
+
+number <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"n0.val"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// We read the value of n0 and store it to number variable</span>
+    
+<span class="token keyword">if</span><span class="token punctuation">(</span>number <span class="token operator">!=</span> <span class="token number">777777</span><span class="token punctuation">)</span><span class="token punctuation">{</span>       <span class="token comment">// 777777is the return value if the code fails to read the new value</span>
+  lastnumber <span class="token operator">=</span> number<span class="token punctuation">;</span>
+  
+<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>number <span class="token operator">==</span> <span class="token number">777777</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    number <span class="token operator">=</span> lastNumber<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">unsigned</span> <span class="token keyword">long</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"n0.val"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the value of numeric box n0</span>
+<span class="token keyword">unsigned</span> <span class="token keyword">long</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"va0.val"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the value of the variable va0</span>
+<span class="token keyword">unsigned</span> <span class="token keyword">int</span> y <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"b0.bco"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Strore to y the color number of the background of button b0</span>
+</code></pre>
+<p><em><strong>NOTE:</strong> Only attributes shown in <strong>green</strong> in the Editor can be both read and changed by user code at runtime.</em><br>
+To</p>
+<h3 id="function-readstr">Function readStr();</h3>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ReadString</code></em></strong></p>
+<p><em><strong>Parameters:</strong></em><br>
+readStr(<code>String</code>)</p>
+<ul>
+<li><strong>String</strong>: objectname.textAttribute (example: “t0.txt”, “va0.txt”, “b0.txt”…etc)</li>
+</ul>
+<p><em><strong>Description:</strong></em><br>
+We use it to read the value of every components’ text attribute from Nextion (txt etc…)</p>
+<p>In case the function fails to read the new value, it will return the text <code>ERROR</code>.<br>
+The reasons of getting <code>ERROR</code>: (from release 1.0.4 and above)</p>
+<ul>
+<li>Serial buffer occupied timeout</li>
+<li>Waiting bytes have not come to Serial timeout</li>
+<li>Command start character is not found in Serial timeout</li>
+<li>The end of the command has not come to Serial</li>
+</ul>
+<p>The chances of getting a wrong value is one in a million.<br>
+You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value.<br>
+You can check it with an <strong><code>if()</code></strong> statement, in which you will ignore the value of <code>ERROR</code> and you can run the <code>readStr()</code> again or set a safe value or use the last good known value method.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp">String text <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>
+String lastText <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>
+
+text <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// We read the value of t0 and store it</span>
+    
+<span class="token keyword">if</span><span class="token punctuation">(</span>text<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"ERROR"</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">{</span>       <span class="token comment">// ERROR is the return value if the code fails to read the new value</span>
+  lastText <span class="token operator">=</span> text<span class="token punctuation">;</span>
+  
+<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>text<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"ERROR"</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    text <span class="token operator">=</span> lastText<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>Syntax:</strong></em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp">String x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the value of text box t0</span>
+</code></pre>
+<h2 id="library-public-variables">Library Public Variables</h2>
+<p><strong><code>Associated Library's Code Example:</code> <em><code>ChangePagesAndSentFloatValues</code></em></strong></p>
+<p><em><strong>1st Variable</strong></em>:<br>
+<em>currentPageId</em><br>
+A variable that stores the ID number of the current page loaded on Nextion. It is <strong>VERY</strong> important that Nextion and Arduino are synced and when you send data, the data goes to the right page.</p>
+<p><strong>NOTE</strong>: In order to update this variable with the current Id of the page, you must write the Preinitialize Event of every page: <code>printh 23 02 50 XX</code> , where <code>XX</code> the id of the page in HEX.<br>
+For page0: <code>printh 23 02 50 00</code><br>
+for page9: <code>printh23 02 50 09</code><br>
+for page10: <code>printh 23 02 50 0A</code></p>
+<p><em>See Appendix at the end of the document for numbers in HEX table</em></p>
+<p>It can be called by writing:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">int</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span>currentPageId<span class="token punctuation">;</span> <span class="token comment">// Store to x the currentPageId</span>
+</code></pre>
+<p><strong>Example</strong>:</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"You are on page0!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+  myObject<span class="token punctuation">.</span><span class="token function">writeStr</span><span class="token punctuation">(</span><span class="token string">"t0.txt"</span><span class="token punctuation">,</span> <span class="token string">"You are on page1!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p><em><strong>2nd Variable</strong></em>:<br>
+<em>lastCurrentPageId</em><br>
+This variable stores the last value of <code>currentPageId</code> before <code>currentPageId</code> is changed. We use it to check if the page we are on has changed, in order to send refreshing screen data to the components of the page.</p>
+<p>After that, it can be set to equal with the <code>currentPageId</code>, in order not to send unnecessary data for refreshing the components.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">!=</span> myObject<span class="token punctuation">.</span>lastCurrentPageId<span class="token punctuation">)</span><span class="token punctuation">{</span>
+  <span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    <span class="token punctuation">[</span>send the data to refresh the page0<span class="token punctuation">]</span>
+  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>myObject<span class="token punctuation">.</span>currentPageId <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+    <span class="token punctuation">[</span>send the data to refresh the page1<span class="token punctuation">]</span>
+  <span class="token punctuation">}</span>
+  myObject<span class="token punctuation">.</span>lastCurrentPageId <span class="token operator">=</span> myObject<span class="token punctuation">.</span>currentPageId<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</code></pre>
+<p>Find more on the Library’s Example:  <em><code>ChangePagesAndSentFloatValues</code></em><br>
+<em><strong>TIP</strong>: You can read the ID of the current Loaded page at anytime, without the use of the Library’s commands using the <code>dp</code> system command</em></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">int</span> x <span class="token operator">=</span> myObject<span class="token punctuation">.</span><span class="token function">readNumber</span><span class="token punctuation">(</span><span class="token string">"dp"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Store to x the ID of the current Loaded page</span>
+</code></pre>
+<h3 id="function-easynexreadcustomcommand">Function easyNexReadCustomCommand()</h3>
+<p><code>easyNexReadCustomCommand()</code> has a weak attribute and will be created only when user<br>
+declares this function in the main code.<br>
+More for custom protocol and commands <a href="https://seithan.com/Easy-Nextion-Library/Custom-Protocol/">https://seithan.com/Easy-Nextion-Library/Custom-Protocol/</a><br>
+Our commands will have this format: <code>#</code>  <code>len</code>   <code>cmd</code>   <code>id</code>   <code>id2</code><br>
+and we must send them from Nextion as HEX with the printh command.<br>
+For example: <code>printh 23 03 4C 01 01</code></p>
+<ul>
+<li><code>#</code> start marker, declares that a command follows</li>
+<li><code>len</code> declares the number of bytes that will be received</li>
+<li><code>cmd</code> declares the task of the command or command group</li>
+<li><code>id</code> declares the properties of the command</li>
+<li><code>id2</code> a second property for the command</li>
+</ul>
+<p>When we send a custom command with the above format, the function NextionListen() will capture the start marker <code>#</code> and the <code>len</code> (first 2 bytes) and it will wait until all the bytes of the command, as we have declared with the <code>len</code> byte, arrive to the Serial buffer and inside the timeout limits.<br>
+After that, the function will read the next byte, which is the command group and the function <code>readCommand()</code> takes over and through a switch command tries to match the <code>_cmd</code> variable that holds the command group value with the statements of the cases.<br>
+If we do NOT have a match with the predefined, <code>cmd</code> of <code>P</code> for page and <code>T</code> for triggers, it will continue to the default where we store the <code>_cmd</code> and <code>_len</code> to the public variables <code>cmdGroup</code> and <code>cmdLenght</code> as we are going to need access to them from the main code in the next step.<br>
+Next we call the the <code>easyNexReadCustomCommand()</code>  with the precondition and ONLY if we have declared the function in the main code.<br>
+From this point we can handle the assign of <code>cmdGroup</code> and <code>IDs</code> from the <code>easyNexReadCustomCommand()</code> in the user code, where we can go on with a switch case<br>
+for the <code>cmdGroup</code>, the one that we have stored the <code>_cmd</code> for public use and we can call it with <code>myObject.cmdGroup</code>. This is why we made <code>cmdGroup</code> a public variable.</p>
+<p>As an example, we use 2 arrays (tables) of integers, where we are going to change the value of the position (element) with custom commands.</p>
+<pre class=" language-cpp"><code class="prism  language-cpp"> <span class="token keyword">int</span> dataL<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">//values 0 or 255, because we use only one byte</span>
+ <span class="token keyword">int</span> dataS<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">// values from 0 to 255, because we use only one byte</span>
+</code></pre>
+<p>The format is the known: <code>#</code>  <code>len</code>   <code>cmd</code>   <code>id</code>   <code>id2</code></p>
+<ul>
+<li>where the <code>id</code> referred to the position (element) of the array we want to write on</li>
+<li>And <code>id2</code> carries the value to be written on the element of array.</li>
+</ul>
+<p>The custom command from Nextion: <code>printh 23 03 4C 00 0A</code></p>
+<ul>
+<li>4C is the Hex for letter L and we refer to the array <code>dataL[]</code></li>
+<li>00 Hex of Dec number 0 used as the index for each array element</li>
+<li>0A Hex of Dec number 10 is the value we are going to write on element 0</li>
+</ul>
+<p>After the command is executed by our code, the values on <code>dataL[]</code> array will be</p>
+<ul>
+<li>dataL[4] = {10,0,0,0}</li>
+</ul>
+<p>Same for the dataS[] intead that cmd is the 53 in Hex for letter <code>S</code></p>
+<pre class=" language-cpp"><code class="prism  language-cpp"><span class="token keyword">void</span> <span class="token function">easyNexReadCustomCommand</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
+
+  <span class="token keyword">int</span> arrayPlace<span class="token punctuation">;</span> <span class="token comment">// temp variable</span>
+  <span class="token keyword">int</span> value<span class="token punctuation">;</span>      <span class="token comment">// temp variable</span>
+  
+  <span class="token keyword">switch</span><span class="token punctuation">(</span>myNex<span class="token punctuation">.</span>cmdGroup<span class="token punctuation">)</span><span class="token punctuation">{</span>
+    
+    <span class="token keyword">case</span> <span class="token string">'L'</span><span class="token operator">:</span> <span class="token comment">// Or &lt;case 0x4C:&gt;  If 'L' matches</span>
+    <span class="token comment">// we are going to write values in specific places in the dataL[] table</span>
+    <span class="token comment">// read the next byte that determines the position on the table</span>
+    arrayPlace <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// read the next byte that keeps the value for the position</span>
+    value <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// update the array with the new values</span>
+    dataL<span class="token punctuation">[</span>arrayPlace<span class="token punctuation">]</span> <span class="token operator">=</span> value<span class="token punctuation">;</span>  
+    
+    <span class="token keyword">break</span><span class="token punctuation">;</span> 
+
+    <span class="token keyword">case</span> <span class="token string">'S'</span><span class="token operator">:</span> <span class="token comment">// Or &lt;case 0x53:&gt;  If 'S' matches </span>
+    
+    <span class="token comment">// we are going to write values in specific places in the dataS[] table</span>
+    <span class="token comment">// from Nextion printh 23 03 53 00 00</span>
+    <span class="token comment">// read the next byte that determines the position on the table</span>
+    arrayPlace <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// read the next byte that keeps the value for the position</span>
+    value <span class="token operator">=</span> myNex<span class="token punctuation">.</span><span class="token function">readByte</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+    
+    <span class="token comment">// update the array with the new values</span>
+    dataS<span class="token punctuation">[</span>arrayPlace<span class="token punctuation">]</span> <span class="token operator">=</span> value<span class="token punctuation">;</span>  
+    
+    <span class="token keyword">break</span><span class="token punctuation">;</span>
+  <span class="token punctuation">}</span>  
+<span class="token punctuation">}</span>
+</code></pre>
+<h2 id="usefull-tips">Usefull Tips</h2>
+<p><strong>Manage Variables</strong><br>
+You can read/write the variables as any other component.</p>
+<p>Use <code>readNumber()</code> to read the value of a numeric variable.<br>
+Example: <code>myNex.readNumber("va0.val");</code><br>
+<strong>BUT:</strong>  <code>myNex.readNumber("sys0");</code></p>
+<p>Use <code>writeNum()</code> to change the value of a numeric variable.<br>
+Example: <code>myNex.writeNum("va0.val", 255);</code><br>
+<strong>BUT:</strong>  <code>myNex.readNumber("sys0", 375);</code></p>
+<p>Use <code>readStr()</code> to read the text of a String variable.<br>
+Example: <code>myNex.readStr("va0.txt");</code></p>
+<p>Use <code>writeStr()</code> to change the text of a String variable.<br>
+Example: <code>myNex.writeStr("va0.txt", "Hello World");</code><br>
+For this to happen, the variables you want to read/write must be at the page you are currently on.<br>
+Otherwise, if the variables are of <strong>global</strong> scope, you will need to use a prefix with the page name that the variables are at.<br>
+Example:<br>
+<code>myNex.readNumber("page0.va0.val");</code> // If the variable is at page0<br>
+The same goes for the other functions as well.</p>
+<h2 id="compatibility">Compatibility</h2>
+<ul>
+<li>Arduino</li>
+<li>ESP</li>
+</ul>
+<p>Tested MCUs:</p>
+<ol>
+<li>Arduino NANO</li>
+<li>Arduino MEGA 2560</li>
+<li>Arduino UNO</li>
+<li>WeMos D1 mini ESP8266</li>
+</ol>
+<h2 id="releases">Releases:</h2>
+<h3 id="release-1.0.5">Release 1.0.5</h3>
+<ul>
+<li>Updated <code>readNumber()</code> function for faster response and more accurate reading.</li>
+<li>Added the <code>readByte()</code> function for reading  Serial buffer from user code</li>
+<li>Added <code>easyNexReadCustomCommand()</code> function with a weak attribute and will be created only when user declares this function in the main code. The motivation to move this function out of the library’s files, comes from Ricardo Reis thanks to his issue <a href="https://github.com/Seithan/EasyNextionLibrary/issues/15">https://github.com/Seithan/EasyNextionLibrary/issues/15</a></li>
+<li>Added public variables <code>cmdGroup</code> and <code>cmdLength</code> <strong>ONLY</strong> for read custom commands, stores the command group ID and the length of the command</li>
+</ul>
+<h3 id="release-1.0.4">Release 1.0.4</h3>
+<ul>
+<li>Added the readStr() function for reading a String from Nextion</li>
+</ul>
+<h3 id="release-1.0.3">Release 1.0.3</h3>
+<p>Two more examples were added.</p>
+<ul>
+<li>The first one demonstrates how to use EasyNextionLibrary with waveforms.</li>
+<li>The  second one demonstrates how to use EasyNextionLibrary with progress bars</li>
+</ul>
+<h3 id="release-1.0.2">Release 1.0.2</h3>
+<ul>
+<li>Remove the private function <code>readCommand()</code> from the main <code>EasyNextionLibrary.cpp</code> file. A new file is created named <code>readCustomCommands.cpp</code>,  in order to make easier the modifications for it when using the custom protocol.</li>
+<li>Return Error code added and to other cases of <code>readNumberFromSerial()</code>. When failing to read a number, we  return the number 777777 instead. The cases of having a 777777 return:
+<ul>
+<li>Waiting bytes have not come to Serial timeout</li>
+<li>Command start character is not found in Serial timeout</li>
+<li>The waiting length of the byte package has not come to Serial</li>
+<li>Bytes on Serial are not the expected</li>
+</ul>
+</li>
+<li>The function readNumberFromSerial() is improved, making reading values more accurate, due to hardware or Serial problems.</li>
+</ul>
+<h2 id="licence">Licence</h2>
+<p>This library is licensed under <strong>MIT X11 license</strong>.<br>
+Copyright © &lt;2020&gt;  Athanasios Seitanis</p>
+<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
+<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
+<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
+<p>Except as contained in this notice, the name of Athanasios Seitanis or the name of EasyNextionLibrary shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Athanasios Seitanis.<br>
+Also, prior written permission is required if this software or any part of it or any modifications of it, are used for commercial purposes.</p>
+<p>By using this software, you agree with the above terms and conditions as they are.<br>
+The owner of the software has the right to change the terms of this license at any time without a prior notification.</p>
+<h2 id="appendix">Appendix</h2>
+<h3 id="numbers-in-hex">Numbers in HEX:</h3>
+
+<table>
+<thead>
+<tr>
+<th>DEC</th>
+<th>HEX</th>
+<th>-</th>
+<th>DEC</th>
+<th>HEX</th>
+<th>-</th>
+<th>DEC</th>
+<th>HEX</th>
+<th>-</th>
+<th>DEC</th>
+<th>HEX</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>0</td>
+<td><strong>00</strong></td>
+<td>-</td>
+<td>16</td>
+<td><strong>10</strong></td>
+<td>-</td>
+<td>32</td>
+<td><strong>20</strong></td>
+<td>-</td>
+<td>48</td>
+<td><strong>30</strong></td>
+</tr>
+<tr>
+<td>1</td>
+<td><strong>01</strong></td>
+<td>-</td>
+<td>17</td>
+<td><strong>11</strong></td>
+<td>-</td>
+<td>33</td>
+<td><strong>21</strong></td>
+<td>-</td>
+<td>49</td>
+<td><strong>31</strong></td>
+</tr>
+<tr>
+<td>2</td>
+<td><strong>02</strong></td>
+<td>-</td>
+<td>18</td>
+<td><strong>12</strong></td>
+<td>-</td>
+<td>34</td>
+<td><strong>22</strong></td>
+<td>-</td>
+<td>50</td>
+<td><strong>32</strong></td>
+</tr>
+<tr>
+<td>3</td>
+<td><strong>03</strong></td>
+<td>-</td>
+<td>19</td>
+<td><strong>13</strong></td>
+<td>-</td>
+<td>35</td>
+<td><strong>23</strong></td>
+<td>-</td>
+<td>51</td>
+<td><strong>33</strong></td>
+</tr>
+<tr>
+<td>4</td>
+<td><strong>04</strong></td>
+<td>-</td>
+<td>20</td>
+<td><strong>14</strong></td>
+<td>-</td>
+<td>36</td>
+<td><strong>24</strong></td>
+<td>-</td>
+<td>52</td>
+<td><strong>34</strong></td>
+</tr>
+<tr>
+<td>5</td>
+<td><strong>05</strong></td>
+<td>-</td>
+<td>21</td>
+<td><strong>15</strong></td>
+<td>-</td>
+<td>37</td>
+<td><strong>25</strong></td>
+<td>-</td>
+<td>53</td>
+<td><strong>35</strong></td>
+</tr>
+<tr>
+<td>6</td>
+<td><strong>06</strong></td>
+<td>-</td>
+<td>22</td>
+<td><strong>16</strong></td>
+<td>-</td>
+<td>38</td>
+<td><strong>26</strong></td>
+<td>-</td>
+<td>54</td>
+<td><strong>36</strong></td>
+</tr>
+<tr>
+<td>7</td>
+<td><strong>07</strong></td>
+<td>-</td>
+<td>23</td>
+<td><strong>17</strong></td>
+<td>-</td>
+<td>39</td>
+<td><strong>27</strong></td>
+<td>-</td>
+<td>55</td>
+<td><strong>37</strong></td>
+</tr>
+<tr>
+<td>8</td>
+<td><strong>08</strong></td>
+<td>-</td>
+<td>24</td>
+<td><strong>18</strong></td>
+<td>-</td>
+<td>40</td>
+<td><strong>28</strong></td>
+<td>-</td>
+<td>56</td>
+<td><strong>38</strong></td>
+</tr>
+<tr>
+<td>9</td>
+<td><strong>09</strong></td>
+<td>-</td>
+<td>25</td>
+<td><strong>19</strong></td>
+<td>-</td>
+<td>41</td>
+<td><strong>29</strong></td>
+<td>-</td>
+<td>57</td>
+<td><strong>39</strong></td>
+</tr>
+<tr>
+<td>10</td>
+<td><strong>0A</strong></td>
+<td>-</td>
+<td>26</td>
+<td><strong>1A</strong></td>
+<td>-</td>
+<td>42</td>
+<td><strong>2A</strong></td>
+<td>-</td>
+<td>58</td>
+<td><strong>3A</strong></td>
+</tr>
+<tr>
+<td>11</td>
+<td><strong>0B</strong></td>
+<td>-</td>
+<td>27</td>
+<td><strong>1B</strong></td>
+<td>-</td>
+<td>43</td>
+<td><strong>2B</strong></td>
+<td>-</td>
+<td>59</td>
+<td><strong>3B</strong></td>
+</tr>
+<tr>
+<td>12</td>
+<td><strong>0C</strong></td>
+<td>-</td>
+<td>28</td>
+<td><strong>1C</strong></td>
+<td>-</td>
+<td>44</td>
+<td><strong>2C</strong></td>
+<td>-</td>
+<td>60</td>
+<td><strong>3C</strong></td>
+</tr>
+<tr>
+<td>13</td>
+<td><strong>0D</strong></td>
+<td>-</td>
+<td>29</td>
+<td><strong>1D</strong></td>
+<td>-</td>
+<td>45</td>
+<td><strong>2D</strong></td>
+<td>-</td>
+<td>61</td>
+<td><strong>3D</strong></td>
+</tr>
+<tr>
+<td>14</td>
+<td><strong>0E</strong></td>
+<td>-</td>
+<td>30</td>
+<td><strong>1E</strong></td>
+<td>-</td>
+<td>46</td>
+<td><strong>2E</strong></td>
+<td>-</td>
+<td>62</td>
+<td><strong>3E</strong></td>
+</tr>
+<tr>
+<td>15</td>
+<td><strong>0F</strong></td>
+<td>-</td>
+<td>31</td>
+<td><strong>1F</strong></td>
+<td>-</td>
+<td>47</td>
+<td><strong>2F</strong></td>
+<td>-</td>
+<td>63</td>
+<td><strong>3F</strong></td>
+</tr>
+</tbody>
+</table></div>
+</body>
+
+</html>

BIN
extras/media/AttributePane.png


BIN
extras/media/EasyNextionLibrary_Arduino_Library_Manager.png


+ 87 - 0
keywords.txt

@@ -0,0 +1,87 @@
+#############################################
+# Syntax Coloring Map for EasyNextionLibrary
+#############################################
+
+#############################################
+# Datatypes (KEYWORD1)
+#############################################
+
+EasyNex	KEYWORD1	EasyNex DATA_TYPE
+myNex	KEYWORD1
+
+#############################################
+# Methods and Functions (KEYWORD2)
+#############################################
+
+NextionListen KEYWORD2
+
+writeStr	KEYWORD2
+writeNum	KEYWORD2
+readNumber	KEYWORD2
+currentPageId	KEYWORD2
+lastCurrentPageId	KEYWORD2
+readNumberFromSerial	KEYWORD2
+
+#############################################
+# Specifies Structures (KEYWORD3)
+#############################################
+
+
+trigger0	KEYWORD3	trigger0	RESERVED_WORD
+trigger1	KEYWORD3	trigger1	RESERVED_WORD
+trigger2	KEYWORD3	trigger2	RESERVED_WORD
+trigger3	KEYWORD3	trigger3	RESERVED_WORD
+trigger4	KEYWORD3	trigger4	RESERVED_WORD
+trigger5	KEYWORD3	trigger5	RESERVED_WORD
+trigger6	KEYWORD3	trigger6	RESERVED_WORD
+trigger7	KEYWORD3	trigger7	RESERVED_WORD
+trigger8	KEYWORD3	trigger8	RESERVED_WORD
+trigger9	KEYWORD3	trigger9	RESERVED_WORD
+trigger10	KEYWORD3	trigger10	RESERVED_WORD
+trigger11	KEYWORD3	trigger11	RESERVED_WORD
+trigger12	KEYWORD3	trigger12	RESERVED_WORD
+trigger13	KEYWORD3	trigger13	RESERVED_WORD
+trigger14	KEYWORD3	trigger14	RESERVED_WORD
+trigger15	KEYWORD3	trigger15	RESERVED_WORD
+trigger16	KEYWORD3	trigger16	RESERVED_WORD
+trigger17	KEYWORD3	trigger17	RESERVED_WORD
+trigger18	KEYWORD3	trigger18	RESERVED_WORD
+trigger19	KEYWORD3	trigger19	RESERVED_WORD
+trigger20	KEYWORD3	trigger20	RESERVED_WORD
+trigger21	KEYWORD3	trigger21	RESERVED_WORD
+trigger22	KEYWORD3	trigger22	RESERVED_WORD
+trigger23	KEYWORD3	trigger23	RESERVED_WORD
+trigger24	KEYWORD3	trigger24	RESERVED_WORD
+trigger25	KEYWORD3	trigger25	RESERVED_WORD
+trigger26	KEYWORD3	trigger26	RESERVED_WORD
+trigger27	KEYWORD3	trigger27	RESERVED_WORD
+trigger28	KEYWORD3	trigger28	RESERVED_WORD
+trigger29	KEYWORD3	trigger29	RESERVED_WORD
+trigger30	KEYWORD3	trigger30	RESERVED_WORD
+trigger31	KEYWORD3	trigger31	RESERVED_WORD
+trigger32	KEYWORD3	trigger32	RESERVED_WORD
+trigger33	KEYWORD3	trigger33	RESERVED_WORD
+trigger34	KEYWORD3	trigger34	RESERVED_WORD
+trigger35	KEYWORD3	trigger35	RESERVED_WORD
+trigger36	KEYWORD3	trigger36	RESERVED_WORD
+trigger37	KEYWORD3	trigger37	RESERVED_WORD
+trigger38	KEYWORD3	trigger38	RESERVED_WORD
+trigger39	KEYWORD3	trigger39	RESERVED_WORD
+trigger40	KEYWORD3	trigger40	RESERVED_WORD
+trigger41	KEYWORD3	trigger41	RESERVED_WORD
+trigger42	KEYWORD3	trigger42	RESERVED_WORD
+trigger43	KEYWORD3	trigger43	RESERVED_WORD
+trigger44	KEYWORD3	trigger44	RESERVED_WORD
+trigger45	KEYWORD3	trigger45	RESERVED_WORD
+trigger46	KEYWORD3	trigger46	RESERVED_WORD
+trigger47	KEYWORD3	trigger47	RESERVED_WORD
+trigger48	KEYWORD3	trigger48	RESERVED_WORD
+trigger49	KEYWORD3	trigger49	RESERVED_WORD
+trigger50	KEYWORD3	trigger50	RESERVED_WORD
+easyNexReadCustomCommand	KEYWORD3	easyNexReadCustomCommand	RESERVED_WORD
+
+
+#############################################
+# Constants (LITERAL1)
+#############################################
+

+ 9 - 0
library.properties

@@ -0,0 +1,9 @@
+name=Easy Nextion Library
+version=1.0.6
+author=Athanasios Seitanis <seithagta@gmail.com>
+maintainer=Athanasios Seitanis <seithagta@gmail.com>
+sentence=Arduino library for Nextion displays
+paragraph=A simple library that uses only four functions. You can easily benefit from Nextion's wide range of features and advantages in just a few easy steps. The library uses a custom protocol that can prove to be a powerful tool for advanced users as it can be easily modified to meet one’s needs.
+category=Display
+url=https://github.com/Seithan/EasyNextionLibrary
+architectures=*

+ 337 - 0
src/EasyNextionLibrary.cpp

@@ -0,0 +1,337 @@
+/*!
+ * EasyNextionLibrary.cpp - Easy library for Nextion Displays
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * All rights reserved under the library's licence
+ */
+
+// include this library's description file
+#ifndef EasyNextionLibrary_h
+#include "EasyNextionLibrary.h"
+#endif
+
+#ifndef trigger_h
+#include "trigger.h"
+#endif
+
+//-------------------------------------------------------------------------
+ // Constructor : Function that handles the creation and setup of instances
+//---------------------------------------------------------------------------
+
+EasyNex::EasyNex(HardwareSerial& serial){  // Constructor's parameter is the Serial we want to use
+  _serial = &serial;
+}
+
+void EasyNex::begin(unsigned long baud){
+  _serial->begin(baud);  // We pass the initialization data to the objects (baud rate) default: 9600
+  
+  delay(100);            // Wait for the Serial to initialize
+  
+  _tmr1 = millis();
+  while(_serial->available() > 0){     // Read the Serial until it is empty. This is used to clear Serial buffer
+    if((millis() - _tmr1) > 400UL){    // Reading... Waiting... But not forever...... 
+      break;                            
+    } 
+      _serial->read();                // Read and delete bytes
+  }
+}
+
+
+/*
+ * -- writeNum(String, uint32_t): for writing in components' numeric attribute
+ * String = objectname.numericAttribute (example: "n0.val"  or "n0.bco".....etc)
+ * uint32_t = value (example: 84)
+ * Syntax: | myObject.writeNum("n0.val", 765);  |  or  | myObject.writeNum("n0.bco", 17531);       |
+ *         | set the value of numeric n0 to 765 |      | set background color of n0 to 17531 (blue)|
+ */
+void EasyNex::writeNum(String compName, uint32_t val){
+	_component = compName;
+	_numVal = val;
+  
+	_serial->print(_component);
+  _serial->print("=");
+  _serial->print(_numVal);
+	_serial->print("\xFF\xFF\xFF");
+}
+
+
+/*
+ * -- writeStr(String, String): for writing in components' text attributes
+ * String No1 = objectname.textAttribute (example: "t0.txt"  or "b0.txt")
+ * String No2 = value (example: "Hello World")
+ * Syntax: | myObject.writeStr("t0.txt", "Hello World");  |  or  | myObject.writeNum("b0.txt", "Button0"); |
+ *         | set the value of textbox t0 to "Hello World" |      | set the text of button b0 to "Button0"  |
+ */
+void EasyNex::writeStr(String command, String txt){ 
+	_component = command;
+	_strVal = txt;
+  
+  if(_strVal == "cmd"){
+    _serial->print(_component);
+    _serial->print("\xFF\xFF\xFF");
+    
+  }else if(_strVal != "cmd"){
+    _serial->print(_component);
+    _serial->print("=\"");
+    _serial->print(_strVal);
+    _serial->print("\"");
+    _serial->print("\xFF\xFF\xFF");
+  }
+}
+
+String EasyNex::readStr(String TextComponent){
+  
+  String _Textcomp = TextComponent;  
+  bool _endOfCommandFound = false;
+  char _tempChar;
+  
+    _tmr1 = millis();  
+  while(_serial->available()){                  // Waiting for NO bytes on Serial, 
+                                                    // as other commands could be sent in that time.
+    if((millis() - _tmr1) > 1000UL){                // Waiting... But not forever...after the timeout 
+      _readString = "ERROR";
+      break;                                // Exit from the loop due to timeout. Return ERROR
+    }else{
+      NextionListen();                      // We run NextionListen(), in case that the bytes on Serial are a part of a command 
+    }
+  }
+  
+  // As there are NO bytes left in Serial, which means no further commands need to be executed,
+  // send a "get" command to Nextion
+  
+  _serial->print("get ");
+  _serial->print(_Textcomp);             // The String of a component you want to read on Nextion
+	_serial->print("\xFF\xFF\xFF");
+  
+  // And now we are waiting for a reurn data in the following format:
+  // 0x70 ... (each character of the String is represented in HEX) ... 0xFF 0xFF 0xFF
+  
+  // Example: For the String ab123, we will receive: 0x70 0x61 0x62 0x31 0x32 0x33 0xFF 0xFF 0xFF
+  
+  _tmr1 = millis();  
+  while(_serial->available() < 4){                  // Waiting for bytes to come to Serial, an empty Textbox will send 4 bytes 
+                                                    // and this the minimmum number that we are waiting for (70 FF FF FF)
+    if((millis() - _tmr1) > 400UL){                // Waiting... But not forever...after the timeout 
+       _readString = "ERROR";
+       break;                        // Exit the loop due to timeout. Return ERROR
+    }
+  }
+  
+  if(_serial->available() > 3){         // Read if more then 3 bytes come (we always wait for more than 3 bytes)
+    _start_char = _serial->read();      //  variable (start_char) read and store the first byte on it  
+    _tmr1 = millis();
+      
+    while(_start_char != 0x70){      // If the return code 0x70 is not detected,
+      if(_serial->available()){      // read the Serial until you find it
+        _start_char = _serial->read();
+      }
+        
+      if((millis() - _tmr1) > 100UL){     // Waiting... But not forever...... 
+        _readString = "ERROR";          // If the 0x70 is not found within the given time, break the while()
+                                        // to avoid being stuck inside the while() loop
+        break;
+      }   
+    }
+      
+    if(_start_char == 0x70){  // If the return code 0x70 is detected,   
+      _readString = "";   // We clear the _readString variable, to avoid any accidentally stored text
+      int _endBytes = 0;  // This variable helps us count the end command bytes of Nextion. The 0xFF 0xFF 0xFF
+      _tmr1 = millis(); 
+      
+      while(_endOfCommandFound == false){  // As long as the three 0xFF bytes have NOT been found, run the commands inside the loop
+        if(_serial->available()){
+          _tempChar = _serial->read();  // Read the first byte of the Serial
+         
+          if(_tempChar == 0xFF || _tempChar == 0xFFFFFFFF){  // If the read byte is the end command byte, 
+            _endBytes++ ;      // Add one to the _endBytes counter
+            if(_endBytes == 3){  
+              _endOfCommandFound = true;  // If the counter is equal to 3, we have the end command
+            }                         
+          }else{ // If the read byte is NOT the end command byte,
+            _readString += _tempChar;  // Add the char to the _readString String variable 
+          }
+        }
+          
+        if((millis() - _tmr1) > 1000UL){     // Waiting... But not forever...... 
+          _readString = "ERROR";           // If the end of the command is NOT found in the time given,
+                                           // break the while
+          break;                           
+        }
+      }
+    }
+  } 
+
+  return _readString;
+}
+
+/*
+ * -- readNumber(String): We use it to read the value of a components' numeric attribute on Nextion
+ * In every component's numeric attribute (value, bco color, pco color...etc)
+ * String = objectname.numericAttribute (example: "n0.val", "n0.pco", "n0.bco"...etc)
+ * Syntax: | myObject.readNumber("n0.val"); |  or  | myObject.readNumber("b0.bco");                       |
+ *         | read the value of numeric n0   |      | read the color number of the background of butoon b0 |
+ */
+
+uint32_t EasyNex::readNumber(String component){
+  
+  _comp = component;
+  bool _endOfCommandFound = false;
+  char _tempChar;
+  
+    _numberValue = 777777;                      // The function will return this number in case it fails to read the new number
+  
+    _tmr1 = millis();  
+  while(_serial->available()){                  // Waiting for NO bytes on Serial, 
+                                                    // as other commands could be sent in that time.
+    if((millis() - _tmr1) > 1000UL){                // Waiting... But not forever...after the timeout 
+      _numberValue = 777777;
+      break;                                // Exit from the loop due to timeout. Return 777777
+    }else{
+      NextionListen();                      // We run NextionListen(), in case that the bytes on Serial are a part of a command 
+    }
+  }
+  
+  
+  // As there are NO bytes left in Serial, which means no further commands need to be executed,
+  // send a "get" command to Nextion
+  
+  _serial->print("get ");
+  _serial->print(_comp);             // The String of a component you want to read on Nextion
+	_serial->print("\xFF\xFF\xFF");
+  
+  // And now we are waiting for a reurn data in the following format:
+  // 0x71 0x01 0x02 0x03 0x04 0xFF 0xFF 0xFF
+  // 0x01 0x02 0x03 0x04 is 4 byte 32-bit value in little endian order.
+
+    _tmr1 = millis();  
+  while(_serial->available() < 8){                  // Waiting for bytes to come to Serial, 
+                                                    // we are waiting for 8 bytes
+    if((millis() - _tmr1) > 400UL){                // Waiting... But not forever...after the timeout 
+       _numberValue = 777777;
+       break;                                  // Exit the loop due to timeout. Return 777777
+    }
+  }
+  
+  if(_serial->available() > 7){         
+    _start_char = _serial->read();      //  variable (start_char) read and store the first byte on it  
+    _tmr1 = millis();
+      
+    while(_start_char != 0x71){      // If the return code 0x71 is not detected,
+      if(_serial->available()){      // read the Serial until you find it
+        _start_char = _serial->read();
+      }
+        
+      if((millis() - _tmr1) > 100UL){     // Waiting... But not forever...... 
+        _numberValue = 777777;          // If the 0x71 is not found within the given time, break the while()
+                                        // to avoid being stuck inside the while() loop
+        break;
+      }   
+    }
+      
+    if(_start_char == 0x71){  // If the return code 0x71 is detected, 
+  
+			for(int i = 0; i < 4; i++){   // Read the 4 bytes represent the number and store them in the numeric buffer 
+		   
+        _numericBuffer[i] = _serial->read();
+	    }
+      
+      
+      int _endBytes = 0;  // This variable helps us count the end command bytes of Nextion. The 0xFF 0xFF 0xFF
+      _tmr1 = millis();  
+      
+      while(_endOfCommandFound == false){  // As long as the three 0xFF bytes have NOT been found, run the commands inside the loop
+        
+        _tempChar = _serial->read();  // Read the next byte of the Serial
+         
+        if(_tempChar == 0xFF || _tempChar == 0xFFFFFFFF){  // If the read byte is the end command byte, 
+          _endBytes++ ;      // Add one to the _endBytes counter
+          if(_endBytes == 3){  
+            _endOfCommandFound = true;  // If the counter is equal to 3, we have the end command
+          }                         
+        }else{ // If the read byte is NOT the end command byte,
+          _numberValue = 777777;
+          break;            
+        }
+          
+        if((millis() - _tmr1) > 1000UL){     // Waiting... But not forever...... 
+          _numberValue = 777777;           // If the end of the command is NOT found in the time given,
+                                           // break the while
+          break;                           
+        }
+      }
+    }
+  }
+  
+  if(_endOfCommandFound == true){
+    // We can continue with the little endian conversion
+    _numberValue = _numericBuffer[3];
+    _numberValue <<= 8;
+    _numberValue |= _numericBuffer[2];
+    _numberValue <<= 8;
+    _numberValue |= _numericBuffer[1];
+    _numberValue <<= 8;
+    _numberValue |= _numericBuffer[0];
+  }else{
+    _numberValue = 777777;
+  }
+  
+  return _numberValue;
+}
+
+/*
+ * -- readByte(): Main purpose and usage is for the custom commands read
+ * Where we need to read bytes from Serial inside user code
+ */
+
+int  EasyNex::readByte(){
+  
+ int _tempInt = _serial->read(); 
+
+ return _tempInt;
+  
+}
+
+
+
+/*
+ * -- NextionListen(): It uses a custom protocol to identify commands from Nextion Touch Events
+ * For advanced users: You can modify the custom protocol to add new group commands.
+ * More info on custom protocol: https://seithan.com/Easy-Nextion-Library/Custom-Protocol/ and on the documentation of the library
+ */
+/*! WARNING: This function must be called repeatedly to response touch events
+ * from Nextion touch panel. 
+ * Actually, you should place it in your loop function.
+ */
+void EasyNex::NextionListen(){
+	if(_serial->available() > 2){         // Read if more then 2 bytes come (we always send more than 2 <#> <len> <cmd> <id>
+    _start_char = _serial->read();      // Create a local variable (start_char) read and store the first byte on it  
+    _tmr1 = millis();
+    
+    while(_start_char != '#'){            
+      _start_char = _serial->read();        // whille the start_char is not the start command symbol 
+                                           //  read the serial (when we read the serial the byte is deleted from the Serial buffer)
+      if((millis() - _tmr1) > 100UL){     //   Waiting... But not forever...... 
+        break;                            
+      }   
+    }
+    if(_start_char == '#'){            // And when we find the character #
+      _len = _serial->read();          //  read and store the value of the second byte
+                                       // <len> is the lenght (number of bytes following) 
+      _tmr1 = millis();
+      _cmdFound = true;
+      
+      while(_serial->available() < _len){     // Waiting for all the bytes that we declare with <len> to arrive              
+        if((millis() - _tmr1) > 100UL){         // Waiting... But not forever...... 
+          _cmdFound = false;                  // tmr_1 a timer to avoid the stack in the while loop if there is not any bytes on _serial
+          break;                            
+        }                                     
+      }                                   
+  
+      if(_cmdFound == true){                  // So..., A command is found (bytes in _serial buffer egual more than len)
+        _cmd1 = _serial->read();              // Read and store the next byte. This is the command group
+        readCommand();                        // We call the readCommand(), 
+                                              // in which we read, seperate and execute the commands 
+			}
+		}
+	}
+}
+

+ 157 - 0
src/EasyNextionLibrary.h

@@ -0,0 +1,157 @@
+/*!
+ * EasyNextionLibrary.h - Easy library for Nextion Displays
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * All rights reserved under the library's licence
+ */
+
+#if ARDUINO >= 100    
+ #include "Arduino.h"
+#else
+ #include "WProgram.h"
+#endif
+
+  //------------------------------------------------------
+ // ensure this library description is only included once
+//--------------------------------------------------------
+#ifndef EasyNextionLibrary_h
+#define EasyNextionLibrary_h
+
+
+
+
+/**************************************************************************/
+/** 
+ *  @brief Class for functions that can easily contol Nextion Displays
+ */
+/**************************************************************************/
+  //---------------------------------------
+ // library interface description
+//-----------------------------------------
+class EasyNex {
+  
+    //--------------------------------------- 
+	 // user-accessible "public" interface
+  //-----------------------------------------
+  
+  /* five main functions of the library:
+   *
+   * -- begin(): the begin() method of the class in which we pass the initialization data to the objects. 
+   * initialization data: unsigned long baud = 9600 (default) if nothing written in the begin()
+   * myObject.begin(115200); for baud rate 115200
+   * 
+   * -- EasyNex(HardwareSerial& serial): The constructor of the class that has the parameter of the Serial we use
+   * EasyNex.myObject(Serial);  or Serial1, Serial2....
+   *
+   * -- writeNum(String, unsigned int): for writing in components' numeric attribute
+   * String = objectname.numericAttribute (example: "n0.val"  or "n0.bco".....etc)
+   * unsigned int = value (example: 84)
+   * Syntax: | myObject.writeNum("n0.val", 765);  |  or  | myObject.writeNum("n0.bco", 17531);       |
+   *         | set the value of numeric n0 to 765 |      | set background color of n0 to 17531 (blue)|
+   * 
+   * 
+   * -- writeStr(String, String): for writing in components' text attributes
+   * String No1 = objectname.textAttribute (example: "t0.txt"  or "b0.txt")
+   * String No2 = value (example: "Hello World")
+   * Syntax: | myObject.writeStr("t0.txt", "Hello World");  |  or  | myObject.writeNum("b0.txt", "Button0"); |
+   *         | set the value of textbox t0 to "Hello World" |      | set the text of button b0 to "Button0"  |
+   * 
+   * -- NextionListen(): It uses a custom protocol to identify commands from Nextion Touch Events
+   * For advanced users: You can modify the custom protocol to add new group commands.
+   * More info on custom protocol: https://www.seithan.com/  and on the documentation of the library
+   * WARNING: This function must be called repeatedly to response touch events
+   * from Nextion touch panel. Actually, you should place it in your loop function.
+   * 
+   * -- readNumber(String): We use it to read the value of a components' numeric attribute
+   * In every component's numeric attribute (value, bco color, pco color...etc)
+   * String = objectname.numericAttribute (example: "n0.val", "n0.pco", "n0.bco"...etc)
+   * Syntax: | myObject.readNumber("n0.val"); |  or  | myObject.readNumber("b0.bco");                       |
+   *         | read the value of numeric n0   |      | read the color number of the background of button b0 |
+   * -- readStr(String): We use it to read the value of every components' text attribute from Nextion (txt etc...)
+   * String = objectname.textAttribute (example: "t0.txt", "va0.txt", "b0.txt"...etc)
+   * Syntax: String x = myObject.readStr("t0.txt"); // Store to x the value of text box t0
+   *
+   * -- readByte() : We read the next byte from the Serial
+   * Main purpose and usage is for the custom commands read
+   * Where we need to read bytes from Serial inside user code
+   * Syntax: | myObject.readByte(); |
+   */
+   
+
+	public:
+    EasyNex(HardwareSerial& serial);
+		void begin(unsigned long baud = 9600);
+    void writeNum(String, uint32_t);
+    void writeStr(String, String txt = "cmd");
+		void NextionListen(void);
+    uint32_t readNumber(String);
+    String readStr(String);
+    int readByte();
+    
+      //--------------------------------------- 
+     // public variables
+    //-----------------------------------------
+    
+    /* currentPageId: shows the id of the current page shown on Nextion
+     * WARNING: At the Preinitialize Event of every page, we must write: 
+     * printh 23 02 50 xx , where xx the id of the page in hex 
+     * (example: for page0, we write: printh 23 02 50 00 , for page9: printh23 02 50 09, for page10: printh 23 02 50 0A) 
+     * Use can call it by writing in the .ino file code:  variable = myObject.currentPageId;
+     * 
+     * lastCurrentPageId: stores the value of the previous page shown on Nextion
+     * No need to write anything in Preinitialize Event on Nextion
+     * You can call it by writing in the .ino file code:  variable = myObject.lastCurrentPageId;
+     *
+     * cmdGroup: ONLY for custom commands stores the command group ID 
+     *
+     * cmdLength: ONLY for custom commands stores the length of the command
+     */ 
+    int currentPageId;  
+    int lastCurrentPageId;
+    byte cmdGroup;
+    byte cmdLength;
+    
+    
+    //--------------------------------------- 
+	 // library-accessible "private" interface
+  //-----------------------------------------
+	private:
+    HardwareSerial* _serial;
+		void readCommand(void);
+    void callTriggerFunction(void);
+    
+      //----------------------------------------------
+     // for function writeNum() (write to numeric attribute)
+    //------------------------------------------------
+		String _component;     // Also used in writeStr()
+    uint32_t _numVal;
+    
+      //--------------------------------------------
+     // for function writeStr() (write to text attribute)
+    //----------------------------------------------
+    String _strVal;
+    
+		  //---------------------------------------
+		 // for function readNumber()
+    //-----------------------------------------
+		String _comp;
+		uint8_t _numericBuffer[4];
+		uint32_t _numberValue;
+    
+      //---------------------------------------
+		 // for General functions  
+    //-----------------------------------------
+    char _start_char;
+    unsigned long _tmr1;
+    boolean _cmdFound;
+    uint8_t _cmd1;
+    uint8_t _len;
+    
+      //---------------------------------------
+		 // for function readStr()
+    //-----------------------------------------  
+    String _readString;
+    
+};
+
+#endif
+

+ 291 - 0
src/callTriggers.cpp

@@ -0,0 +1,291 @@
+/*!
+ * callTriggers.cpp - Easy library for Nextion Displays
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * All rights reserved under the library's licence
+ */
+
+/*! We made a separate file < callTriggers.cpp > for the function callTriggerFunction(), 
+ *  as it would be too long to fit in the EasyNextionLibrary.cpp, because there are
+ *  50 predefined cases for the triggers and it is easier for someone to edit them
+ */
+
+#ifndef EasyNextionLibrary_h
+#include "EasyNextionLibrary.h"
+#endif                        
+                                
+#ifndef trigger_h
+#include "trigger.h"
+#endif
+
+void EasyNex::callTriggerFunction(){
+  
+ uint8_t _tempRead = _serial->read();  // We read the next byte, which, according to our protocol, is the < Trigger ID >
+                                // From Nextion we send: < printh 23 02 54 xx >
+                                // (where xx is the trigger id in HEX, 01 for 1, 02 for 2, ... 0A for 10 etc)
+  switch(_tempRead){
+    
+    case 0x00:
+      trigger0();
+      break;    
+    
+    case 0x01:
+      trigger1();
+      break;
+
+    case 0x02:
+      trigger2();
+      break;
+           
+    case 0x03:
+      trigger3();
+      break;
+                 
+    case 0x04:
+      trigger4();
+      break;    
+                 
+    case 0x05:
+      trigger5();
+      break;   
+    
+    case 0x06:
+      trigger6();
+      break;
+
+    case 0x07:
+      trigger7();
+      break;
+           
+    case 0x08:
+      trigger8();
+      break;
+                 
+    case 0x09:
+      trigger9();
+      break;    
+                 
+    case 0x0A:
+      trigger10();
+      break;
+    
+    case 0x0B:
+      trigger11();
+      break;
+
+    case 0x0C:
+      trigger12();
+      break;
+           
+    case 0x0D:
+      trigger13();
+      break;
+                 
+    case 0x0E:
+      trigger14();
+      break;    
+                 
+    case 0x0F:
+      trigger15();
+      break;   
+    
+    case 0x10:
+      trigger16();
+      break;
+
+    case 0x11:
+      trigger17();
+      break;
+           
+    case 0x12:
+      trigger18();
+      break;
+                 
+    case 0x13:
+      trigger19();
+      break;    
+                 
+    case 0x14:
+      trigger20();
+      break; 
+
+    case 0x15:
+      trigger21();
+      break;
+
+    case 0x16:
+      trigger22();
+      break;
+           
+    case 0x17:
+      trigger23();
+      break;
+                 
+    case 0x18:
+      trigger24();
+      break;    
+                 
+    case 0x19:
+      trigger25();
+      break;   
+    
+    case 0x1A:
+      trigger26();
+      break;
+
+    case 0x1B:
+      trigger27();
+      break;
+           
+    case 0x1C:
+      trigger28();
+      break;
+                 
+    case 0x1D:
+      trigger29();
+      break;    
+                 
+    case 0x1E:
+      trigger30();
+      break;
+    
+    case 0x1F:
+      trigger31();
+      break;
+
+    case 0x20:
+      trigger32();
+      break;
+           
+    case 0x21:
+      trigger33();
+      break;
+                 
+    case 0x22:
+      trigger34();
+      break;    
+                 
+    case 0x23:
+      trigger35();
+      break;   
+    
+    case 0x24:
+      trigger36();
+      break;
+
+    case 0x25:
+      trigger37();
+      break;
+           
+    case 0x26:
+      trigger38();
+      break;
+                 
+    case 0x27:
+      trigger39();
+      break;    
+                 
+    case 0x28:
+      trigger40();
+      break; 
+    
+    case 0x29:
+      trigger41();
+      break;
+
+    case 0x2A:
+      trigger42();
+      break;
+           
+    case 0x2B:
+      trigger43();
+      break;
+                 
+    case 0x2C:
+      trigger44();
+      break;    
+                 
+    case 0x2D:
+      trigger45();
+      break;   
+    
+    case 0x2E:
+      trigger46();
+      break;
+
+    case 0x2F:
+      trigger47();
+      break;
+           
+    case 0x30:
+      trigger48();
+      break;
+                 
+    case 0x31:
+      trigger49();
+      break;    
+                 
+    case 0x32:
+      trigger50();
+      break;
+
+    case 0x40:
+      trigger64();
+      break;
+    
+    case 0x41:
+      trigger65();
+      break;
+    
+    case 0x42:
+      trigger66();
+      break;
+    
+    case 0x43:
+      trigger67();
+      break;
+    
+    case 0x48:
+      trigger72();
+      break;
+    
+    case 0x49:
+      trigger73();
+      break;
+
+    case 0x50:
+      trigger80();
+      break;
+    
+    case 0x51:
+      trigger81();
+      break;
+
+    case 0x52:
+      trigger82();
+      break;
+    
+    case 0x53:
+      trigger83();
+      break;
+    
+    case 0x54:
+      trigger84();
+      break;
+
+    case 0x55:
+      trigger85();
+      break;
+    
+    case 0x56:
+      trigger86();
+      break;
+
+    case 0x57:
+      trigger87();
+      break;
+    
+    case 0x58:
+      trigger88();
+      break;
+  }
+}

+ 146 - 0
src/readCustomCommands.cpp

@@ -0,0 +1,146 @@
+/*!
+ * readCustomCommands.cpp - Easy library for Nextion Displays
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * All rights reserved under the library's licence
+ */
+
+// include this library's description file
+#ifndef EasyNextionLibrary_h
+#include "EasyNextionLibrary.h"
+#endif
+
+#ifndef trigger_h
+#include "trigger.h"
+#endif
+// This was a part of the NextionListen(), but we seperated it, 
+// in order to make easier the modifications for it, especially in the case of a custom protocol
+// Now, we only have two command groups: the "Trigger" and "Page"
+
+void EasyNex::readCommand(){
+
+				
+  switch(_cmd1){
+    case 'P': /*or <case 0x50:>  If 'P' matches, we have the command group "Page". 
+               *The next byte is the page <Id> according to our protocol.
+               *
+               * We have write in every page's "preinitialize page" the command
+               *  printh 23 02 50 xx (where xx is the page id in HEX, 00 for 0, 01 for 1, etc).
+               * <<<<Every event written on Nextion's pages preinitialize page event will run every time the page is Loaded>>>>
+               *  it is importand to let the Arduino "Know" when and which Page change.
+               */
+      lastCurrentPageId = currentPageId;
+      currentPageId = _serial->read();                   
+      break;
+      
+      
+    case 'T':   /* Or <case 0x54:>  If 'T' matches, we have the command group "Trigger". 
+                 * The next byte is the trigger <Id> according to our protocol.
+                 *
+                 * We have to write in a Touch Event on Nextion the following: < printh 23 02 54 xx >
+                 * (where xx is the trigger id in HEX, 01 for 1, 02 for 2, ... 0A for 10 etc).
+                 * With the switch(){case}, we call a predefined void with prefixed names
+                 * as we have declare them on trigger.cpp file. Starting from trigger0()......up to trigger50()
+                 * The maximum number of predefined void is 255
+                 * We declare the trigger() at this file: trigger.cpp
+                 * 
+                 * You can use the trigger() in your code as a function, 
+                 * in order to write any kind of code and run it, by sending the < printh > command needed,
+                 * from a Touch event on Nextion, such as pressing a button. Example:
+                 */
+                /**                   void trigger0(){
+                                        digitalWrite(13, HIGH); // sets the digital pin 13 on
+                                        delay(1000);            // waits for a second
+                                        digitalWrite(13, LOW);  // sets the digital pin 13 off
+                                      }
+                 */
+                /* In Touch Press Event of a button on Nextion write <printh 23 02 54 01>
+                 * Every time we press the Button the command <printh 23 02 54 01> will be sent over Serial
+                 * Then, the library will call the void trigger1()
+                 * the code inside the trigger1() will run once ...
+                 */
+      callTriggerFunction(); // We made a separate file callTriggers.cpp for this function, 
+                             // as it would be too long to fit in here, because there are
+                             // 50 predefined cases for the triggers. 
+      break;
+    
+    default:
+      cmdGroup = _cmd1;  // stored in the public variable cmdGroup for later use in the main code
+      cmdLength = _len;  // stored in the public variable cmdLength for later use in the main code
+      easyNexReadCustomCommand();
+                    
+      break;
+               
+            /*   More for custom protocol and commands https://seithan.com/Easy-Nextion-Library/Custom-Protocol/
+               
+      easyNexReadCustomCommand() has a weak attribute and will be created only when user
+      declare this function on the main code
+      More for custom protocol and commands https://seithan.com/Easy-Nextion-Library/Custom-Protocol/
+      our commands will have this format: <#> <len> <cmd> <id> <id2>
+      and we must send them from Nextion as HEX with the printh command
+      like: printh 23 03 4C 01 01
+
+      <#> start marker, declares that a command is followed
+      <len> declares the number of bytes that will follow
+      <cmd> declares the task of the command or command group
+      <id> declares the properties of the command
+      <id2> a second property of the command
+      
+      When we send a custom command with the above format, the function NextionListen() will capture the start marker # and the len (first 2 bytes)
+      and it will wait until all the bytes of the command, as we have declared with the len byte, arrive to the Serial buffer and inside the timeout limits.
+      
+      After that, the function will read the next byte, which is the command group and the function readCommand() takes over and through a switch command
+      tries to match the _cmd variable that holds the command group value with the statements of the cases.
+      
+      If we do NOT have a match with the predefined, cmd of P for page and T for triggers, it will continue to the default where we store the _cmd and _len to the public variables
+      cmdGroup and cmdLenght as we are going to need access to them from the main code in the next step.
+      
+      Next we call the the easyNexReadCustomCommand() with the precondition and ONLY if we have declared the function in the main code.
+      
+      From this point we can handle the assign of cmdGroup and IDs from the easyNexReadCustomCommand() in the user code, where we can go on with a switch case
+      for the cmdGroup, the one that we have stored the _cmd for public use and we can call it with myObject.cmdGroup. This is why we made cmdGroup a public variable.
+                     */
+  }
+}
+
+
+/*
+ abstract from main code
+
+void easyNexReadCustomCommand(){
+
+  int arrayPlace; // temp variable
+  int value;      // temp variable
+  
+  switch(myNex.cmdGroup){
+    
+    case 'L': // Or <case 0x4C:>  If 'L' matches
+    // we are going to write values in specific places in the dataL[] table
+    // read the next byte that determines the position on the table
+    arrayPlace = myNex.readByte();
+    
+    // read the next byte that keeps the value for the position
+    value = myNex.readByte();
+    
+    // update the array with the new values
+    dataL[arrayPlace] = value;  
+    
+    break; 
+
+    case 'S': // Or <case 0x53:>  If 'S' matches 
+    
+    // we are going to write values in specific places in the dataS[] table
+    // from Nextion printh 23 03 53 00 00
+    // read the next byte that determines the position on the table
+    arrayPlace = myNex.readByte();
+    
+    // read the next byte that keeps the value for the position
+    value = myNex.readByte();
+    
+    // update the array with the new values
+    dataS[arrayPlace] = value;  
+    
+    break;
+  }  
+}
+*/
+

+ 240 - 0
src/trigger.h

@@ -0,0 +1,240 @@
+/*!
+ * trigger.cpp - Easy library for Nextion Displays
+ * Copyright (c) 2020 Athanasios Seitanis < seithagta@gmail.com >. 
+ * All rights reserved under the library's licence
+ */
+
+/*! We separate this file from the EasyNextionLibrary.cpp in order to make easier the modifications for it
+ * and for simplifying reasons instead of dealing with a large code file.
+ 
+ * if you want to change the name of the predefined voids that I made,(trigger1, trigger2....etc)
+ * you must change:
+   1. The name from "declare the functions"  
+       ---------(example: extern void trigger1(); -> extern void myFunction();)
+
+   2. The name from "declaration of the function as weak"  
+    (example: extern void trigger1() __attribute__((weak)); ---> extern void myFunction() __attribute__((weak));)
+
+   3. the predefined name in the switch(){case} for the trigger command group at the callTriggers.cpp file
+   
+ * With the same way, you can add as many extern void as you like
+ * NOTE: WE can have UP TO 255 extern void
+ *
+ * When a function has a weak attribute it will be created only when user
+ * declare this function on the main code
+ */
+
+
+#ifndef trigger_h
+#define trigger_h
+
+// weak attribute funcion for read the custom command protocol
+
+extern void easyNexReadCustomCommand();
+extern void easyNexReadCustomCommand() __attribute__((weak));
+
+// declare the functions for triggers
+extern void trigger0();
+extern void trigger1(); 
+extern void trigger2();
+extern void trigger3();
+extern void trigger4();
+extern void trigger5();
+extern void trigger6();
+extern void trigger7();
+extern void trigger8();
+extern void trigger9();
+extern void trigger10();
+extern void trigger11();
+extern void trigger12();
+extern void trigger13();
+extern void trigger14();
+extern void trigger15();
+extern void trigger16();
+extern void trigger17();
+extern void trigger18();
+extern void trigger19();
+extern void trigger20();
+extern void trigger21();
+extern void trigger22();
+extern void trigger23();
+extern void trigger24();
+extern void trigger25();
+extern void trigger26();
+extern void trigger27();
+extern void trigger28();
+extern void trigger29();
+extern void trigger30();
+extern void trigger31();
+extern void trigger32();
+extern void trigger33();
+extern void trigger34();
+extern void trigger35();
+extern void trigger36();
+extern void trigger37();
+extern void trigger38();
+extern void trigger39();
+extern void trigger40();
+extern void trigger41();
+extern void trigger42();
+extern void trigger43();
+extern void trigger44();
+extern void trigger45();
+extern void trigger46();
+extern void trigger47();
+extern void trigger48();
+extern void trigger49();
+extern void trigger50();
+extern void trigger51();
+extern void trigger52();
+extern void trigger53();
+extern void trigger54();
+extern void trigger55();
+extern void trigger56();
+extern void trigger57();
+extern void trigger58();
+extern void trigger59();
+extern void trigger60();
+extern void trigger61();
+extern void trigger62();
+extern void trigger63();
+extern void trigger64();
+extern void trigger65();
+extern void trigger66();
+extern void trigger67();
+extern void trigger68();
+extern void trigger69();
+extern void trigger70();
+extern void trigger71();
+extern void trigger72();
+extern void trigger73();
+extern void trigger74();
+extern void trigger75();
+extern void trigger76();
+extern void trigger77();
+extern void trigger78();
+extern void trigger79();
+extern void trigger80();
+extern void trigger81();
+extern void trigger82();
+extern void trigger83();
+extern void trigger84();
+extern void trigger85();
+extern void trigger86();
+extern void trigger87();
+extern void trigger88();
+extern void trigger89();
+extern void trigger90();
+extern void trigger91();
+extern void trigger92();
+extern void trigger93();
+extern void trigger94();
+extern void trigger95();
+extern void trigger96();
+extern void trigger97();
+extern void trigger98();
+extern void trigger99();
+
+// declaration of the function as weak
+extern void trigger0() __attribute__((weak));
+extern void trigger1() __attribute__((weak));
+extern void trigger2() __attribute__((weak));
+extern void trigger3() __attribute__((weak));
+extern void trigger4() __attribute__((weak));
+extern void trigger5() __attribute__((weak));
+extern void trigger6() __attribute__((weak));
+extern void trigger7() __attribute__((weak));
+extern void trigger8() __attribute__((weak));
+extern void trigger9() __attribute__((weak));
+extern void trigger10() __attribute__((weak));
+extern void trigger11() __attribute__((weak));
+extern void trigger12() __attribute__((weak));
+extern void trigger13() __attribute__((weak));
+extern void trigger14() __attribute__((weak));
+extern void trigger15() __attribute__((weak));
+extern void trigger16() __attribute__((weak));
+extern void trigger17() __attribute__((weak));
+extern void trigger18() __attribute__((weak));
+extern void trigger19() __attribute__((weak));
+extern void trigger20() __attribute__((weak));
+extern void trigger21() __attribute__((weak));
+extern void trigger22() __attribute__((weak));
+extern void trigger23() __attribute__((weak));
+extern void trigger24() __attribute__((weak));
+extern void trigger25() __attribute__((weak));
+extern void trigger26() __attribute__((weak));
+extern void trigger27() __attribute__((weak));
+extern void trigger28() __attribute__((weak));
+extern void trigger29() __attribute__((weak));
+extern void trigger30() __attribute__((weak));
+extern void trigger31() __attribute__((weak));
+extern void trigger32() __attribute__((weak));
+extern void trigger33() __attribute__((weak));
+extern void trigger34() __attribute__((weak));
+extern void trigger35() __attribute__((weak));
+extern void trigger36() __attribute__((weak));
+extern void trigger37() __attribute__((weak));
+extern void trigger38() __attribute__((weak));
+extern void trigger39() __attribute__((weak));
+extern void trigger40() __attribute__((weak));
+extern void trigger41() __attribute__((weak));
+extern void trigger42() __attribute__((weak));
+extern void trigger43() __attribute__((weak));
+extern void trigger44() __attribute__((weak));
+extern void trigger45() __attribute__((weak));
+extern void trigger46() __attribute__((weak));
+extern void trigger47() __attribute__((weak));
+extern void trigger48() __attribute__((weak));
+extern void trigger49() __attribute__((weak));
+extern void trigger50() __attribute__((weak));
+extern void trigger51() __attribute__((weak));
+extern void trigger52() __attribute__((weak));
+extern void trigger53() __attribute__((weak));
+extern void trigger54() __attribute__((weak));
+extern void trigger55() __attribute__((weak));
+extern void trigger56() __attribute__((weak));
+extern void trigger57() __attribute__((weak));
+extern void trigger58() __attribute__((weak));
+extern void trigger59() __attribute__((weak));
+extern void trigger60() __attribute__((weak));
+extern void trigger61() __attribute__((weak));
+extern void trigger62() __attribute__((weak));
+extern void trigger63() __attribute__((weak));
+extern void trigger64() __attribute__((weak));
+extern void trigger65() __attribute__((weak));
+extern void trigger66() __attribute__((weak));
+extern void trigger67() __attribute__((weak));
+extern void trigger68() __attribute__((weak));
+extern void trigger69() __attribute__((weak));
+extern void trigger70() __attribute__((weak));
+extern void trigger71() __attribute__((weak));
+extern void trigger72() __attribute__((weak));
+extern void trigger73() __attribute__((weak));
+extern void trigger74() __attribute__((weak));
+extern void trigger75() __attribute__((weak));
+extern void trigger76() __attribute__((weak));
+extern void trigger77() __attribute__((weak));
+extern void trigger78() __attribute__((weak));
+extern void trigger79() __attribute__((weak));
+extern void trigger80() __attribute__((weak));
+extern void trigger81() __attribute__((weak));
+extern void trigger82() __attribute__((weak));
+extern void trigger83() __attribute__((weak));
+extern void trigger84() __attribute__((weak));
+extern void trigger85() __attribute__((weak));
+extern void trigger86() __attribute__((weak));
+extern void trigger87() __attribute__((weak));
+extern void trigger88() __attribute__((weak));
+extern void trigger89() __attribute__((weak));
+extern void trigger90() __attribute__((weak));
+extern void trigger91() __attribute__((weak));
+extern void trigger92() __attribute__((weak));
+extern void trigger93() __attribute__((weak));
+extern void trigger94() __attribute__((weak));
+extern void trigger95() __attribute__((weak));
+extern void trigger96() __attribute__((weak));
+extern void trigger97() __attribute__((weak));
+extern void trigger98() __attribute__((weak));
+extern void trigger99() __attribute__((weak));
+
+#endif