1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Update docs

This commit is contained in:
Rhys Weatherley
2012-06-10 10:52:14 +10:00
parent ac10b9ed5e
commit 448ca56a5a
187 changed files with 2763 additions and 526 deletions

View File

@@ -90,138 +90,165 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include &lt;WProgram.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="preprocessor">#define LCD_BACK_LIGHT 3 // LCD backlight is on D3</span>
<a name="l00031"></a>00031 <span class="preprocessor">#define LCD_BACK_LIGHT 3 // Default LCD backlight is on D3</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define LCD_BUTTON_PIN A0 // Button state is on A0</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#define DEBOUNCE_DELAY 10 // Delay in ms to debounce buttons</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span>
<a name="l00115"></a>00115 <span class="keywordtype">void</span> LCD::init()
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117 <span class="comment">// The Freetronics display is 16x2.</span>
<a name="l00118"></a>00118 begin(16, 2);
<a name="l00119"></a>00119
<a name="l00120"></a>00120 <span class="comment">// Set the LCD back light to be initially on.</span>
<a name="l00121"></a>00121 pinMode(LCD_BACK_LIGHT, OUTPUT);
<a name="l00122"></a>00122 digitalWrite(LCD_BACK_LIGHT, HIGH);
<a name="l00123"></a>00123
<a name="l00124"></a>00124 <span class="comment">// Initialise button input.</span>
<a name="l00125"></a>00125 pinMode(LCD_BUTTON_PIN, INPUT);
<a name="l00126"></a>00126 digitalWrite(LCD_BUTTON_PIN, LOW);
<a name="l00127"></a>00127 prevButton = LCD_BUTTON_NONE;
<a name="l00128"></a>00128 debounceButton = LCD_BUTTON_NONE;
<a name="l00129"></a>00129 lastDebounce = 0;
<a name="l00130"></a>00130 eatRelease = <span class="keyword">false</span>;
<a name="l00131"></a>00131
<a name="l00132"></a>00132 <span class="comment">// Initialize screen saver.</span>
<a name="l00133"></a>00133 timeout = 0;
<a name="l00134"></a>00134 lastRestore = millis();
<a name="l00135"></a>00135 screenSaved = <span class="keyword">false</span>;
<a name="l00136"></a>00136 mode = <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>;
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138
<a name="l00148"></a><a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89">00148</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LCD::display</a>()
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LiquidCrystal::display</a>();
<a name="l00151"></a>00151 digitalWrite(LCD_BACK_LIGHT, HIGH);
<a name="l00130"></a>00130 <span class="keywordtype">void</span> LCD::init()
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132 <span class="comment">// The Freetronics display is 16x2.</span>
<a name="l00133"></a>00133 begin(16, 2);
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="comment">// Configure the backlight pin, but don&#39;t activate it yet in</span>
<a name="l00136"></a>00136 <span class="comment">// case the application sets it to something else during setup().</span>
<a name="l00137"></a>00137 <span class="comment">// Initialization will be forced in the first call to getButton().</span>
<a name="l00138"></a>00138 _backlightPin = LCD_BACK_LIGHT;
<a name="l00139"></a>00139 backlightInit = <span class="keyword">false</span>;
<a name="l00140"></a>00140
<a name="l00141"></a>00141 <span class="comment">// Initialise button input.</span>
<a name="l00142"></a>00142 pinMode(LCD_BUTTON_PIN, INPUT);
<a name="l00143"></a>00143 digitalWrite(LCD_BUTTON_PIN, LOW);
<a name="l00144"></a>00144 prevButton = LCD_BUTTON_NONE;
<a name="l00145"></a>00145 debounceButton = LCD_BUTTON_NONE;
<a name="l00146"></a>00146 lastDebounce = 0;
<a name="l00147"></a>00147 eatRelease = <span class="keyword">false</span>;
<a name="l00148"></a>00148
<a name="l00149"></a>00149 <span class="comment">// Initialize screen saver.</span>
<a name="l00150"></a>00150 timeout = 0;
<a name="l00151"></a>00151 lastRestore = millis();
<a name="l00152"></a>00152 screenSaved = <span class="keyword">false</span>;
<a name="l00153"></a>00153 lastRestore = millis();
<a name="l00153"></a>00153 mode = <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>;
<a name="l00154"></a>00154 }
<a name="l00155"></a>00155
<a name="l00163"></a><a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108">00163</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LCD::noDisplay</a>()
<a name="l00164"></a>00164 {
<a name="l00165"></a>00165 <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>)
<a name="l00166"></a>00166 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LiquidCrystal::noDisplay</a>();
<a name="l00167"></a>00167 digitalWrite(LCD_BACK_LIGHT, LOW);
<a name="l00168"></a>00168 screenSaved = <span class="keyword">true</span>;
<a name="l00169"></a>00169 }
<a name="l00170"></a>00170
<a name="l00206"></a><a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801">00206</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801" title="Sets the current screen saver mode.">LCD::setScreenSaverMode</a>(<a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28" title="Screen saver mode that controls the display and back light.">ScreenSaverMode</a> mode)
<a name="l00182"></a><a class="code" href="classLCD.html#a0b9b3b954290e7a3d94cdc829582b0a8">00182</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a0b9b3b954290e7a3d94cdc829582b0a8" title="Sets the back light pin for the LCD shield.">LCD::setBacklightPin</a>(uint8_t pin)
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184 <span class="keywordflow">if</span> (_backlightPin != pin) {
<a name="l00185"></a>00185 <span class="keywordflow">if</span> (backlightInit) {
<a name="l00186"></a>00186 <span class="comment">// Restore the previous backlight pin to input, floating.</span>
<a name="l00187"></a>00187 pinMode(_backlightPin, INPUT);
<a name="l00188"></a>00188 digitalWrite(_backlightPin, LOW);
<a name="l00189"></a>00189
<a name="l00190"></a>00190 <span class="comment">// Need to re-initialize the backlight at the earliest opportunity.</span>
<a name="l00191"></a>00191 backlightInit = <span class="keyword">false</span>;
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 _backlightPin = pin;
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196
<a name="l00206"></a><a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89">00206</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LCD::display</a>()
<a name="l00207"></a>00207 {
<a name="l00208"></a>00208 <span class="keywordflow">if</span> (this-&gt;mode != mode) {
<a name="l00209"></a>00209 this-&gt;mode = mode;
<a name="l00210"></a>00210 <span class="keywordflow">if</span> (screenSaved)
<a name="l00211"></a>00211 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>();
<a name="l00212"></a>00212 <span class="keywordflow">else</span>
<a name="l00213"></a>00213 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216
<a name="l00232"></a><a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f">00232</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f" title="Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...">LCD::enableScreenSaver</a>(<span class="keywordtype">int</span> timeoutSecs)
<a name="l00233"></a>00233 {
<a name="l00234"></a>00234 <span class="keywordflow">if</span> (timeoutSecs &lt; 0)
<a name="l00235"></a>00235 timeout = 0;
<a name="l00236"></a>00236 <span class="keywordflow">else</span>
<a name="l00237"></a>00237 timeout = ((<span class="keywordtype">unsigned</span> long)timeoutSecs) * 1000;
<a name="l00238"></a>00238 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00239"></a>00239 }
<a name="l00240"></a>00240
<a name="l00246"></a><a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e">00246</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e" title="Disables the screen saver.">LCD::disableScreenSaver</a>()
<a name="l00247"></a>00247 {
<a name="l00248"></a>00248 timeout = 0;
<a name="l00249"></a>00249 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251
<a name="l00259"></a>00259 <span class="comment">// Button mapping table generated by genlookup.c</span>
<a name="l00260"></a>00260 <span class="keyword">static</span> prog_uint8_t <span class="keyword">const</span> buttonMappings[] PROGMEM = {
<a name="l00261"></a>00261 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
<a name="l00262"></a>00262 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
<a name="l00263"></a>00263 };
<a name="l00264"></a>00264 <span class="preprocessor">#define mapButton(value) (pgm_read_byte(&amp;(buttonMappings[(value) &gt;&gt; 5])))</span>
<a name="l00265"></a>00265 <span class="preprocessor"></span>
<a name="l00291"></a><a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292">00291</a> <span class="keywordtype">int</span> <a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event.">LCD::getButton</a>()
<a name="l00292"></a>00292 {
<a name="l00293"></a>00293 <span class="comment">// Read the currently pressed button.</span>
<a name="l00294"></a>00294 <span class="keywordtype">int</span> button = mapButton(analogRead(LCD_BUTTON_PIN));
<a name="l00295"></a>00295
<a name="l00296"></a>00296 <span class="comment">// Debounce the button state.</span>
<a name="l00297"></a>00297 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentTime = millis();
<a name="l00298"></a>00298 <span class="keywordflow">if</span> (button != debounceButton)
<a name="l00299"></a>00299 lastDebounce = currentTime;
<a name="l00300"></a>00300 debounceButton = button;
<a name="l00301"></a>00301 <span class="keywordflow">if</span> ((currentTime - lastDebounce) &lt; DEBOUNCE_DELAY)
<a name="l00302"></a>00302 button = prevButton;
<a name="l00303"></a>00303
<a name="l00304"></a>00304 <span class="comment">// Process the button event if the state has changed.</span>
<a name="l00305"></a>00305 <span class="keywordflow">if</span> (prevButton == LCD_BUTTON_NONE &amp;&amp; button != LCD_BUTTON_NONE) {
<a name="l00306"></a>00306 prevButton = button;
<a name="l00307"></a>00307 <span class="keywordflow">if</span> (screenSaved) {
<a name="l00308"></a>00308 <span class="comment">// Button pressed when screen saver active.</span>
<a name="l00309"></a>00309 <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a>) {
<a name="l00310"></a>00310 <span class="comment">// Turn on the back light only if Select was pressed.</span>
<a name="l00311"></a>00311 <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT) {
<a name="l00312"></a>00312 digitalWrite(LCD_BACK_LIGHT, HIGH);
<a name="l00313"></a>00313 screenSaved = <span class="keyword">false</span>;
<a name="l00314"></a>00314 }
<a name="l00315"></a>00315 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>) {
<a name="l00316"></a>00316 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00317"></a>00317 eatRelease = <span class="keyword">true</span>;
<a name="l00318"></a>00318 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00319"></a>00319 } <span class="keywordflow">else</span> {
<a name="l00320"></a>00320 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a> &amp;&amp; button != LCD_BUTTON_SELECT) {
<a name="l00323"></a>00323 eatRelease = <span class="keyword">false</span>;
<a name="l00324"></a>00324 <span class="keywordflow">return</span> button;
<a name="l00325"></a>00325 }
<a name="l00326"></a>00326 eatRelease = <span class="keyword">false</span>;
<a name="l00327"></a>00327 lastRestore = currentTime;
<a name="l00328"></a>00328 <span class="keywordflow">return</span> button;
<a name="l00329"></a>00329 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prevButton != LCD_BUTTON_NONE &amp;&amp; button == LCD_BUTTON_NONE) {
<a name="l00330"></a>00330 button = -prevButton;
<a name="l00331"></a>00331 prevButton = LCD_BUTTON_NONE;
<a name="l00332"></a>00332 lastRestore = currentTime;
<a name="l00333"></a>00333 <span class="keywordflow">if</span> (eatRelease) {
<a name="l00334"></a>00334 eatRelease = <span class="keyword">false</span>;
<a name="l00335"></a>00335 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00336"></a>00336 }
<a name="l00337"></a>00337 <span class="keywordflow">return</span> button;
<a name="l00338"></a>00338 } <span class="keywordflow">else</span> {
<a name="l00339"></a>00339 <span class="keywordflow">if</span> (!screenSaved &amp;&amp; prevButton == LCD_BUTTON_NONE &amp;&amp;
<a name="l00340"></a>00340 timeout != 0 &amp;&amp; (currentTime - lastRestore) &gt;= timeout)
<a name="l00341"></a>00341 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>(); <span class="comment">// Activate screen saver.</span>
<a name="l00342"></a>00342 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00343"></a>00343 }
<a name="l00344"></a>00344 }
<a name="l00208"></a>00208 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LiquidCrystal::display</a>();
<a name="l00209"></a>00209 pinMode(_backlightPin, OUTPUT);
<a name="l00210"></a>00210 digitalWrite(_backlightPin, HIGH);
<a name="l00211"></a>00211 screenSaved = <span class="keyword">false</span>;
<a name="l00212"></a>00212 backlightInit = <span class="keyword">true</span>;
<a name="l00213"></a>00213 lastRestore = millis();
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215
<a name="l00223"></a><a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108">00223</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LCD::noDisplay</a>()
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225 <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>)
<a name="l00226"></a>00226 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LiquidCrystal::noDisplay</a>();
<a name="l00227"></a>00227 pinMode(_backlightPin, OUTPUT);
<a name="l00228"></a>00228 digitalWrite(_backlightPin, LOW);
<a name="l00229"></a>00229 screenSaved = <span class="keyword">true</span>;
<a name="l00230"></a>00230 backlightInit = <span class="keyword">true</span>;
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00268"></a><a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801">00268</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801" title="Sets the current screen saver mode.">LCD::setScreenSaverMode</a>(<a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28" title="Screen saver mode that controls the display and back light.">ScreenSaverMode</a> mode)
<a name="l00269"></a>00269 {
<a name="l00270"></a>00270 <span class="keywordflow">if</span> (this-&gt;mode != mode) {
<a name="l00271"></a>00271 this-&gt;mode = mode;
<a name="l00272"></a>00272 <span class="keywordflow">if</span> (screenSaved)
<a name="l00273"></a>00273 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>();
<a name="l00274"></a>00274 <span class="keywordflow">else</span>
<a name="l00275"></a>00275 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277 }
<a name="l00278"></a>00278
<a name="l00294"></a><a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f">00294</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f" title="Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...">LCD::enableScreenSaver</a>(<span class="keywordtype">int</span> timeoutSecs)
<a name="l00295"></a>00295 {
<a name="l00296"></a>00296 <span class="keywordflow">if</span> (timeoutSecs &lt; 0)
<a name="l00297"></a>00297 timeout = 0;
<a name="l00298"></a>00298 <span class="keywordflow">else</span>
<a name="l00299"></a>00299 timeout = ((<span class="keywordtype">unsigned</span> long)timeoutSecs) * 1000;
<a name="l00300"></a>00300 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00301"></a>00301 }
<a name="l00302"></a>00302
<a name="l00308"></a><a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e">00308</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e" title="Disables the screen saver.">LCD::disableScreenSaver</a>()
<a name="l00309"></a>00309 {
<a name="l00310"></a>00310 timeout = 0;
<a name="l00311"></a>00311 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00312"></a>00312 }
<a name="l00313"></a>00313
<a name="l00321"></a>00321 <span class="comment">// Button mapping table generated by genlookup.c</span>
<a name="l00322"></a>00322 <span class="keyword">static</span> prog_uint8_t <span class="keyword">const</span> buttonMappings[] PROGMEM = {
<a name="l00323"></a>00323 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
<a name="l00324"></a>00324 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
<a name="l00325"></a>00325 };
<a name="l00326"></a>00326 <span class="preprocessor">#define mapButton(value) (pgm_read_byte(&amp;(buttonMappings[(value) &gt;&gt; 5])))</span>
<a name="l00327"></a>00327 <span class="preprocessor"></span>
<a name="l00353"></a><a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292">00353</a> <span class="keywordtype">int</span> <a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event.">LCD::getButton</a>()
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355 <span class="comment">// Initialize the backlight for the first time if necessary.</span>
<a name="l00356"></a>00356 <span class="keywordflow">if</span> (!backlightInit)
<a name="l00357"></a>00357 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00358"></a>00358
<a name="l00359"></a>00359 <span class="comment">// Read the currently pressed button.</span>
<a name="l00360"></a>00360 <span class="keywordtype">int</span> button = mapButton(analogRead(LCD_BUTTON_PIN));
<a name="l00361"></a>00361
<a name="l00362"></a>00362 <span class="comment">// Debounce the button state.</span>
<a name="l00363"></a>00363 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentTime = millis();
<a name="l00364"></a>00364 <span class="keywordflow">if</span> (button != debounceButton)
<a name="l00365"></a>00365 lastDebounce = currentTime;
<a name="l00366"></a>00366 debounceButton = button;
<a name="l00367"></a>00367 <span class="keywordflow">if</span> ((currentTime - lastDebounce) &lt; DEBOUNCE_DELAY)
<a name="l00368"></a>00368 button = prevButton;
<a name="l00369"></a>00369
<a name="l00370"></a>00370 <span class="comment">// Process the button event if the state has changed.</span>
<a name="l00371"></a>00371 <span class="keywordflow">if</span> (prevButton == LCD_BUTTON_NONE &amp;&amp; button != LCD_BUTTON_NONE) {
<a name="l00372"></a>00372 prevButton = button;
<a name="l00373"></a>00373 <span class="keywordflow">if</span> (screenSaved) {
<a name="l00374"></a>00374 <span class="comment">// Button pressed when screen saver active.</span>
<a name="l00375"></a>00375 <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a>) {
<a name="l00376"></a>00376 <span class="comment">// Turn on the back light only if Select was pressed.</span>
<a name="l00377"></a>00377 <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT) {
<a name="l00378"></a>00378 pinMode(_backlightPin, OUTPUT);
<a name="l00379"></a>00379 digitalWrite(_backlightPin, HIGH);
<a name="l00380"></a>00380 screenSaved = <span class="keyword">false</span>;
<a name="l00381"></a>00381 backlightInit = <span class="keyword">true</span>;
<a name="l00382"></a>00382 }
<a name="l00383"></a>00383 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>) {
<a name="l00384"></a>00384 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00385"></a>00385 eatRelease = <span class="keyword">true</span>;
<a name="l00386"></a>00386 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00387"></a>00387 } <span class="keywordflow">else</span> {
<a name="l00388"></a>00388 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00389"></a>00389 }
<a name="l00390"></a>00390 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a> &amp;&amp; button != LCD_BUTTON_SELECT) {
<a name="l00391"></a>00391 eatRelease = <span class="keyword">false</span>;
<a name="l00392"></a>00392 <span class="keywordflow">return</span> button;
<a name="l00393"></a>00393 }
<a name="l00394"></a>00394 eatRelease = <span class="keyword">false</span>;
<a name="l00395"></a>00395 lastRestore = currentTime;
<a name="l00396"></a>00396 <span class="keywordflow">return</span> button;
<a name="l00397"></a>00397 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prevButton != LCD_BUTTON_NONE &amp;&amp; button == LCD_BUTTON_NONE) {
<a name="l00398"></a>00398 button = -prevButton;
<a name="l00399"></a>00399 prevButton = LCD_BUTTON_NONE;
<a name="l00400"></a>00400 lastRestore = currentTime;
<a name="l00401"></a>00401 <span class="keywordflow">if</span> (eatRelease) {
<a name="l00402"></a>00402 eatRelease = <span class="keyword">false</span>;
<a name="l00403"></a>00403 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00404"></a>00404 }
<a name="l00405"></a>00405 <span class="keywordflow">return</span> button;
<a name="l00406"></a>00406 } <span class="keywordflow">else</span> {
<a name="l00407"></a>00407 <span class="keywordflow">if</span> (!screenSaved &amp;&amp; prevButton == LCD_BUTTON_NONE &amp;&amp;
<a name="l00408"></a>00408 timeout != 0 &amp;&amp; (currentTime - lastRestore) &gt;= timeout)
<a name="l00409"></a>00409 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>(); <span class="comment">// Activate screen saver.</span>
<a name="l00410"></a>00410 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00411"></a>00411 }
<a name="l00412"></a>00412 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
@@ -238,7 +265,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
</iframe>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Fri Jun 1 2012 14:29:16 for ArduinoLibs by&#160;
<hr class="footer"/><address class="footer"><small>Generated on Sun Jun 10 2012 10:51:56 for ArduinoLibs by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>