You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MicroMDAEPiano/third-party/LiquidMenu/doc/Doxygen/html/_b_serial_menu_8ino-example...

80 lines
14 KiB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LiquidMenu: B_serial_menu.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="logo_small.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">LiquidMenu
&#160;<span id="projectnumber">1.4.1</span>
</div>
<div id="projectbrief">Menu creation Arduino library for LCDs, wraps LiquidCrystal.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">B_serial_menu.ino</div> </div>
</div><!--header-->
<div class="contents">
<p>This example uses the serial communication to execute commands.</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * LiquidMenu library - serial_menu.ino</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This example uses the serial communication to execute commands.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * The available commands will be printed on the serial monitor.</span></div><div class="line"><span class="comment"> * This example uses attached callback functions which are explained</span></div><div class="line"><span class="comment"> * in the functions_menu.ino example.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * The circuit:</span></div><div class="line"><span class="comment"> * https://github.com/VasilKalchev/LiquidMenu/blob/master/examples/B_serial_menu/serial_menu.png</span></div><div class="line"><span class="comment"> * - LCD RS pin to Arduino pin 12</span></div><div class="line"><span class="comment"> * - LCD E pin to Arduino pin 11</span></div><div class="line"><span class="comment"> * - LCD D4 pin to Arduino pin 5</span></div><div class="line"><span class="comment"> * - LCD D5 pin to Arduino pin 4</span></div><div class="line"><span class="comment"> * - LCD D6 pin to Arduino pin 3</span></div><div class="line"><span class="comment"> * - LCD D7 pin to Arduino pin 2</span></div><div class="line"><span class="comment"> * - LCD R/W pin to ground</span></div><div class="line"><span class="comment"> * - LCD VSS pin to ground</span></div><div class="line"><span class="comment"> * - LCD VDD pin to 5V</span></div><div class="line"><span class="comment"> * - 10k ohm potentiometer: ends to 5V and ground, wiper to LCD V0</span></div><div class="line"><span class="comment"> * - 150 ohm resistor from 5V to LCD Anode</span></div><div class="line"><span class="comment"> * - LCD Cathode to ground</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Created July 24, 2016</span></div><div class="line"><span class="comment"> * by Vasil Kalchev</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * https://github.com/VasilKalchev/LiquidMenu</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;LiquidCrystal.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_liquid_menu_8h.html">LiquidMenu.h</a>&gt;</span></div><div class="line"></div><div class="line"><span class="comment">// Pin mapping for the display</span></div><div class="line"><span class="keyword">const</span> byte LCD_RS = 12;</div><div class="line"><span class="keyword">const</span> byte LCD_E = 11;</div><div class="line"><span class="keyword">const</span> byte LCD_D4 = 5;</div><div class="line"><span class="keyword">const</span> byte LCD_D5 = 4;</div><div class="line"><span class="keyword">const</span> byte LCD_D6 = 3;</div><div class="line"><span class="keyword">const</span> byte LCD_D7 = 2;</div><div class="line"><span class="comment">//LCD R/W pin to ground</span></div><div class="line"><span class="comment">//10K potentiometer wiper to VO</span></div><div class="line">LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);</div><div class="line"></div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="class_liquid_line.html">LiquidLine</a> welcome_line1(1, 0, <span class="stringliteral">&quot;LiquidMenu &quot;</span>, <a name="a1"></a><a class="code" href="_liquid_menu_8h.html#a7189c07575adbb1070c89dcd0ab5e272">LIQUIDMENU_VERSION</a>);</div><div class="line"><a class="code" href="class_liquid_line.html">LiquidLine</a> welcome_line2(1, 1, <span class="stringliteral">&quot;Serial example&quot;</span>);</div><div class="line"><a name="_a2"></a><a class="code" href="class_liquid_screen.html">LiquidScreen</a> welcome_screen(welcome_line1, welcome_line2);</div><div class="line"></div><div class="line"><a class="code" href="class_liquid_line.html">LiquidLine</a> line21(4, 0, <span class="stringliteral">&quot;Screen 2&quot;</span>);</div><div class="line"><a class="code" href="class_liquid_line.html">LiquidLine</a> type_line(4, 1, <span class="stringliteral">&quot;type...&quot;</span>);</div><div class="line"><a class="code" href="class_liquid_screen.html">LiquidScreen</a> screen2(line21, type_line);</div><div class="line"></div><div class="line"><a class="code" href="class_liquid_line.html">LiquidLine</a> line31(4, 0, <span class="stringliteral">&quot;Screen 3&quot;</span>);</div><div class="line"><a class="code" href="class_liquid_screen.html">LiquidScreen</a> screen3(line31, type_line);</div><div class="line"></div><div class="line"><a class="code" href="class_liquid_line.html">LiquidLine</a> line41(4, 0, <span class="stringliteral">&quot;Screen 4&quot;</span>);</div><div class="line"><a class="code" href="class_liquid_screen.html">LiquidScreen</a> screen4(line41, type_line);</div><div class="line"></div><div class="line"><a name="_a3"></a><a class="code" href="class_liquid_menu.html">LiquidMenu</a> menu(lcd, welcome_screen, screen2, screen3, screen4);</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * This function will be attached to one or more LiquidLine</span></div><div class="line"><span class="comment"> * objects and will be called when the line is focused and</span></div><div class="line"><span class="comment"> * bool LiquidMenu::call_function(byte number) is called with</span></div><div class="line"><span class="comment"> * number - the number specified when attaching the function.</span></div><div class="line"><span class="comment"> * More on this in the function_menu.ino example.</span></div><div class="line"><span class="comment">*/</span></div><div class="line"><span class="keywordtype">void</span> callback_function() {</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot;You called the callback function.&quot;</span>));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup() {</div><div class="line"> Serial.begin(250000);</div><div class="line"></div><div class="line"> lcd.begin(16, 2);</div><div class="line"></div><div class="line"> <span class="comment">// Here we attach the function defined earlier to four LiquidLine objects.</span></div><div class="line"> line21.attach_function(1, callback_function);</div><div class="line"> line31.attach_function(1, callback_function);</div><div class="line"> line41.attach_function(1, callback_function);</div><div class="line"> type_line.attach_function(1, callback_function);</div><div class="line"></div><div class="line"> menu.update();</div><div class="line"></div><div class="line"> Serial.print(F(<span class="stringliteral">&quot;LiquidMenu &quot;</span>)); Serial.print(<a class="code" href="_liquid_menu_8h.html#a7189c07575adbb1070c89dcd0ab5e272">LIQUIDMENU_VERSION</a>); Serial.println(F(<span class="stringliteral">&quot; - Serial example:&quot;</span>));</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot;To navigate the menu type &#39;menu.next_screen()&#39; or &#39;menu.previous_screen()&#39;.&quot;</span>));</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot;To switch focus type &#39;menu.switch_focus()&#39;.&quot;</span>));</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot;To call the callback function type &#39;menu.call_function(1)&#39;.&quot;</span>));</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot;To adjust the focus position type &#39;menu.set_focusPosition(Position::LEFT)&#39;&quot;</span>));</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot; or &#39;menu.set_focusPosition(Position::RIGHT)&#39;.&quot;</span>));</div><div class="line"> Serial.println(F(<span class="stringliteral">&quot;To update the display type &#39;menu.update()&#39;.&quot;</span>)); Serial.println();</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop() {</div><div class="line"> <span class="comment">// This handles the serial input.</span></div><div class="line"> <span class="keywordflow">while</span> (Serial.available() &gt; 0) {</div><div class="line"> String command = Serial.readStringUntil(<span class="charliteral">&#39;\0&#39;</span>);</div><div class="line"> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.next_screen()&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> menu.next_screen();</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.previous_screen()&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> menu.previous_screen();</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.switch_focus()&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> menu.switch_focus(); <span class="comment">// switches focus to the next line</span></div><div class="line"> <span class="comment">// focus is used with functions (see &#39;functions_menu&#39; example)</span></div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.call_function(1)&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> <span class="comment">// The attached function is called.</span></div><div class="line"> menu.call_function(1);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.set_focusPosition(Position::LEFT)&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> <span class="comment">// this function sets the focus position</span></div><div class="line"> menu.set_focusPosition(Position::LEFT);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.set_focusPosition(Position::RIGHT)&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> menu.set_focusPosition(Position::RIGHT);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (command == <span class="stringliteral">&quot;menu.update()&quot;</span>) {</div><div class="line"> Serial.println(command);</div><div class="line"> menu.update();</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> Serial.print(command); Serial.println(F(<span class="stringliteral">&quot; - unknown command&quot;</span>));</div><div class="line"> }</div><div class="line"> menu.update();</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>