mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
163 lines
12 KiB
HTML
163 lines
12 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"/>
|
|
<title>ArduinoLibs: Hello World for Freetronics LCD</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body onload='searchBox.OnSelectItem(0);'>
|
|
<!-- Generated by Doxygen 1.7.4 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div id="top">
|
|
<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>
|
|
<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 id="searchli">
|
|
<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>
|
|
</div>
|
|
<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>
|
|
<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"><pre class="fragment"><span class="preprocessor">#include <LCD.h></span>
|
|
<a class="code" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields.">LCD</a> lcd;
|
|
</pre></div></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"><pre class="fragment"><a class="code" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields.">LCD</a> lcd(A1);
|
|
</pre></div><p>The next step is to enable the screen saver and print some text in the <code>setup</code> function:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setup() {
|
|
lcd.<a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f" title="Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...">enableScreenSaver</a>();
|
|
lcd.print(<span class="stringliteral">"hello, world!"</span>);
|
|
}
|
|
</pre></div></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"><pre class="fragment"><span class="keywordtype">void</span> loop() {
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(millis() / 1000);
|
|
</pre></div></p>
|
|
<p>We then print the name of the button that is currently pressed:</p>
|
|
<div class="fragment"><pre class="fragment"> lcd.setCursor(8, 1);
|
|
<span class="keywordtype">int</span> button = lcd.<a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event.">getButton</a>();
|
|
<span class="keywordflow">if</span> (button == LCD_BUTTON_LEFT)
|
|
lcd.print(<span class="stringliteral">"LEFT"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_RIGHT)
|
|
lcd.print(<span class="stringliteral">"RIGHT"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_UP)
|
|
lcd.print(<span class="stringliteral">"UP"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_DOWN)
|
|
lcd.print(<span class="stringliteral">"DOWN"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT)
|
|
lcd.print(<span class="stringliteral">"SELECT"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button < 0) <span class="comment">// button release</span>
|
|
lcd.print(<span class="stringliteral">" "</span>);
|
|
}
|
|
</pre></div></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"><pre class="fragment"><span class="comment">/*</span>
|
|
<span class="comment">This example demonstrates how to use the LCD library, which extends the</span>
|
|
<span class="comment">standard LiquidCrystal library to provide support for the Freetronics back light</span>
|
|
<span class="comment">and Up/Down/Left/Right/Select buttons. More information on the shield here:</span>
|
|
<span class="comment"></span>
|
|
<span class="comment">http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide</span>
|
|
<span class="comment"></span>
|
|
<span class="comment">This example is placed into the public domain.</span>
|
|
<span class="comment">*/</span>
|
|
|
|
<span class="preprocessor">#include <LCD.h></span>
|
|
<a class="code" href="classLCD.html" title="Enhanced library for Freetronics 16x2 LCD shields.">LCD</a> lcd;
|
|
|
|
<span class="comment">// Note: if you are using the USBDroid and have reassigned pin D9 on the LCD shield to some</span>
|
|
<span class="comment">// other pin (e.g. A1), then you will need to initialize the shield with something like:</span>
|
|
<span class="comment">// LCD lcd(A1);</span>
|
|
<span class="comment">// See also: http://www.freetronics.com/pages/combining-the-lcd-keypad-shield-and-the-usbdroid</span>
|
|
|
|
<span class="keywordtype">void</span> setup() {
|
|
lcd.<a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f" title="Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...">enableScreenSaver</a>();
|
|
lcd.print(<span class="stringliteral">"hello, world!"</span>);
|
|
}
|
|
|
|
<span class="keywordtype">void</span> loop() {
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(millis() / 1000);
|
|
|
|
lcd.setCursor(8, 1);
|
|
<span class="keywordtype">int</span> button = lcd.<a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event.">getButton</a>();
|
|
<span class="keywordflow">if</span> (button == LCD_BUTTON_LEFT)
|
|
lcd.print(<span class="stringliteral">"LEFT"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_RIGHT)
|
|
lcd.print(<span class="stringliteral">"RIGHT"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_UP)
|
|
lcd.print(<span class="stringliteral">"UP"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_DOWN)
|
|
lcd.print(<span class="stringliteral">"DOWN"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT)
|
|
lcd.print(<span class="stringliteral">"SELECT"</span>);
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> (button < 0) <span class="comment">// button release</span>
|
|
lcd.print(<span class="stringliteral">" "</span>);
|
|
}
|
|
|
|
</pre></div> </div></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></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>
|
|
|
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 29 2012 15:23:58 for ArduinoLibs by 
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
|
</body>
|
|
</html>
|