~ekez/tui-webpage

cf1e9173047b69d947f3cd30bd19ac80c7e4fe3c — Zeke Medley 7 days ago db950c0
Fix spelling errors
1 files changed, 6 insertions(+), 5 deletions(-)

M public/non-arduino-ide.html
M public/non-arduino-ide.html => public/non-arduino-ide.html +6 -5
@@ 101,13 101,14 @@
<span id="cb1-8"><a href="#cb1-8"></a>    Serial.print(<span class="st">&quot;: &quot;</span> + message + <span class="st">&quot;</span><span class="sc">\n</span><span class="st">&quot;</span>);</span>
<span id="cb1-9"><a href="#cb1-9"></a>  }</span>
<span id="cb1-10"><a href="#cb1-10"></a>}</span></code></pre></div>
<p>An interesting feature of this ‘serial’ style of interaction is that it is neither unique to Arduinos nor the Arduino IDE. We can communicate with our Arduino via this method using essentially whatever language or method we’d like. Let’s take a look at how we might do so uding the <a href="https://python.org">Python programming langauge</a>.</p>
<p>An interesting feature of this ‘serial’ style of interaction is that it is neither unique to Arduinos nor the Arduino IDE. We can communicate with our Arduino via this method using essentially whatever language or method we’d like. Let’s take a look at how we might do so using the <a href="https://python.org">Python programming language</a>.</p>
<p>Python is a nice choice for this task as its syntax is designed to be relatively human readable even if you don’t know the language and it has an extensive echosystem of libraries to interface with other systems.</p>
<h3 id="getting-set-up">Getting set up</h3>
<p>Start by following the directions <a href="https://wiki.python.org/moin/BeginnersGuide/Download">here</a> to install Python if you do not have it installed already. Having done that you ought to be able to open the Terminal / Command Prompt application on macOS / Windows and run python by typing <code>python</code>.</p>
<p>Here is an example python session in my terminal where I ask the langauge to print <code>hello!</code> to the screen:</p>
<p>Here is an example python session in my terminal where I ask the language to print <code>hello!</code> to the screen:</p>
<pre><code>$ python3
&gt;&gt;&gt; print(&#39;hello!&#39;)hello!
&gt;&gt;&gt; print(&#39;hello!&#39;)
hello!
&gt;&gt;&gt; exit()</code></pre>
<p>Having installed python we can install a library to interface with the Arduino’s serial port by running the following command in our terminals:</p>
<pre><code>$ python3 -m pip install pyserial</code></pre>


@@ 175,7 176,7 @@ please input the port number that your port is on: 5
<p>Performing this interaction in the Arduino IDE produces a less than desirable result. In order to send data to the Arduino via the IDE you are required to type your input into the text box and then press enter. This effectively transforms the interaction from ‘press r five times’ to ‘press r followed by enter 5 times.’</p>
<p>An advantage of using our Python script is that we no longer have this constraint. We can send input to the user whenever we would like with <code>serial.write()</code>.</p>
<p>In order to do this I’ve provided a python script which exposes a <code>getch</code> function. <code>getch</code> reads a character from input on the terminal without requiring that the user presses enter. You can find the source code <a href="https://git.sr.ht/~ekez/tui-webpage/tree/master/item/examples/getch.py">here</a> along with instructions on using it at the top of the file.</p>
<p>Here’s an example of a program that sends a number to the arduino representing the amount of time that has passed between when the user last pressed a key and the current keypress. This program uses the functions from the two provided python programs to do this:</p>
<p>Here’s an example of a program that sends a number to the Arduino representing the amount of time that has passed between when the user last pressed a key and the current key press. This program uses the functions from the two provided python programs to do this:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1"></a><span class="kw">def</span> get_time():</span>
<span id="cb7-2"><a href="#cb7-2"></a>    <span class="cf">return</span> <span class="bu">round</span>(time.time() <span class="op">*</span> <span class="dv">1000</span>)</span>
<span id="cb7-3"><a href="#cb7-3"></a></span>


@@ 204,7 205,7 @@ please input the port number that your port is on: 5
<ol type="1">
<li>Implement the task from homework 2 but without requiring the user to press enter between letters.</li>
<li>Light up a LED on the Arduino according to how quickly the user is pressing buttons.</li>
<li>Write an arduino program to light up a LED according to numbers being sent over the serial interface (<code>Serial.parseInt()</code> may be helpful here) and then use python to send some information about your computers internet connection to the Arduino.</li>
<li>Write an Arduino program to light up a LED according to numbers being sent over the serial interface (<code>Serial.parseInt()</code> may be helpful here) and then use python to send some information about your computers internet connection to the Arduino.</li>
</ol>
</body>
</html>