mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
175 lines
14 KiB
HTML
175 lines
14 KiB
HTML
<!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.6"/>
|
|
<title>ArduinoLibs: Hello World for Freetronics LCD</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/search.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
|
</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 style="padding-left: 0.5em;">
|
|
<div id="projectname">ArduinoLibs
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.6 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
</script>
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li>
|
|
<div id="MSearchBox" class="MSearchBoxInactive">
|
|
<span class="left">
|
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
alt=""/>
|
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
|
</span><span class="right">
|
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Pages</a></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><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Hello World for Freetronics <a class="el" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields. ">LCD</a> </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="textblock"><p>The <a class="el" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields. ">LCD</a> class provides an enhanced version of the standard Arduino <a href="http://arduino.cc/en/Reference/LiquidCrystal">LiquidCrystal</a> library that supports the additional features of the <a href="http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide">Freetronics LCD</a> shield; namely the back light and the Up, Down, Left, Right, and Select buttons. This tutorial explains how to use the <a class="el" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields. ">LCD</a> class to perform basic text output and to use the enhanced shield features.</p>
|
|
<div class="image">
|
|
<img src="HelloWorld.png" alt="HelloWorld.png"/>
|
|
</div>
|
|
<p>We start by including the library and initializing it:</p>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include <LCD.h></span></div>
|
|
<div class="line"><a class="code" href="classLCD.html">LCD</a> lcd;</div>
|
|
</div><!-- fragment --></p>
|
|
<p>Unlike the LiquidCrystal library we don't normally need to specify the pin assignments for this shield. The one exception is when the shield is used with the USBDroid and the D9 pin is reassigned as described on <a href="http://www.freetronics.com/pages/combining-the-lcd-keypad-shield-and-the-usbdroid">this page</a>. In that case, the initialization sequence would look something like this instead:</p>
|
|
<div class="fragment"><div class="line"><a class="code" href="classLCD.html">LCD</a> lcd(A1);</div>
|
|
</div><!-- fragment --><p>The next step is to enable the screen saver and print some text in the <code>setup</code> function:</p>
|
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> setup() {</div>
|
|
<div class="line"> lcd.<a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f">enableScreenSaver</a>();</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"hello, world!"</span>);</div>
|
|
<div class="line">}</div>
|
|
</div><!-- fragment --></p>
|
|
<p>The screen saver is a built-in feature of the <a class="el" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields. ">LCD</a> class that turns off the display and the back light after a specific timeout (the default is 10 seconds). Pressing any of the keys on the shield or calling <a class="el" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light. ">LCD::display()</a> will wake up the screen again.</p>
|
|
<p>In the program's <code>loop</code> function we print the number of seconds since startup to the second line of the <a class="el" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields. ">LCD</a> display:</p>
|
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> loop() {</div>
|
|
<div class="line"> lcd.setCursor(0, 1);</div>
|
|
<div class="line"> lcd.print(millis() / 1000);</div>
|
|
</div><!-- fragment --></p>
|
|
<p>We then print the name of the button that is currently pressed:</p>
|
|
<div class="fragment"><div class="line"> lcd.setCursor(8, 1);</div>
|
|
<div class="line"> <span class="keywordtype">int</span> button = lcd.<a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292">getButton</a>();</div>
|
|
<div class="line"> <span class="keywordflow">if</span> (button == LCD_BUTTON_LEFT)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"LEFT"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_RIGHT)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"RIGHT"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_UP)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"UP"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_DOWN)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"DOWN"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"SELECT"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button < 0) <span class="comment">// button release</span></div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">" "</span>);</div>
|
|
<div class="line">}</div>
|
|
</div><!-- fragment --></p>
|
|
<p>The <a class="el" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event. ">LCD::getButton()</a> function returns the key that has been pressed or released, or LCD_BUTTON_NONE if no key has been pressed or released this time through the loop.</p>
|
|
<p>The full source code for the example follows:</p>
|
|
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
|
|
<div class="line"><span class="comment">This example demonstrates how to use the LCD library, which extends the</span></div>
|
|
<div class="line"><span class="comment">standard LiquidCrystal library to provide support for the Freetronics back light</span></div>
|
|
<div class="line"><span class="comment">and Up/Down/Left/Right/Select buttons. More information on the shield here:</span></div>
|
|
<div class="line"><span class="comment"></span></div>
|
|
<div class="line"><span class="comment">http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide</span></div>
|
|
<div class="line"><span class="comment"></span></div>
|
|
<div class="line"><span class="comment">This example is placed into the public domain.</span></div>
|
|
<div class="line"><span class="comment">*/</span></div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="preprocessor">#include <LCD.h></span></div>
|
|
<div class="line"><a class="code" href="classLCD.html">LCD</a> lcd;</div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="comment">// Note: if you are using the USBDroid and have reassigned pin D9 on the LCD shield to some</span></div>
|
|
<div class="line"><span class="comment">// other pin (e.g. A1), then you will need to initialize the shield with something like:</span></div>
|
|
<div class="line"><span class="comment">// LCD lcd(A1);</span></div>
|
|
<div class="line"><span class="comment">// See also: http://www.freetronics.com/pages/combining-the-lcd-keypad-shield-and-the-usbdroid</span></div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">void</span> setup() {</div>
|
|
<div class="line"> lcd.<a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f">enableScreenSaver</a>();</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"hello, world!"</span>);</div>
|
|
<div class="line">}</div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">void</span> loop() {</div>
|
|
<div class="line"> lcd.setCursor(0, 1);</div>
|
|
<div class="line"> lcd.print(millis() / 1000);</div>
|
|
<div class="line"></div>
|
|
<div class="line"> lcd.setCursor(8, 1);</div>
|
|
<div class="line"> <span class="keywordtype">int</span> button = lcd.<a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292">getButton</a>();</div>
|
|
<div class="line"> <span class="keywordflow">if</span> (button == LCD_BUTTON_LEFT)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"LEFT"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_RIGHT)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"RIGHT"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_UP)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"UP"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_DOWN)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"DOWN"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT)</div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">"SELECT"</span>);</div>
|
|
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (button < 0) <span class="comment">// button release</span></div>
|
|
<div class="line"> lcd.print(<span class="stringliteral">" "</span>);</div>
|
|
<div class="line">}</div>
|
|
<div class="line"></div>
|
|
</div><!-- fragment --> </div></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated on Sat Mar 14 2015 15:47:30 for ArduinoLibs by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.6
|
|
</small></address>
|
|
</body>
|
|
</html>
|