1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/blink_blink.html
Rhys Weatherley 25eb9d2eb6 Update docs
2018-02-18 09:12:45 +10:00

129 lines
9.2 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: Blinking LED Example</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&#160;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&#160;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">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</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">Blinking LED Example </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <a class="el" href="classBlinkLED.html" title="Blink a LED on a digital output pin. ">BlinkLED</a> class provides support logic for blinking a LED connected to an output pin. The traditional way to blink a LED uses a delay loop:</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> loop() {</div>
<div class="line"> digitalWrite(13, HIGH);</div>
<div class="line"> delay(1000);</div>
<div class="line"> digitalWrite(13, LOW);</div>
<div class="line"> delay(1000);</div>
<div class="line">}</div>
</div><!-- fragment --><p>The problem with this code is that the entire application is blocked during the <code>delay()</code>. No other activities can be serviced. <a class="el" href="classBlinkLED.html" title="Blink a LED on a digital output pin. ">BlinkLED</a> provides a re-entrant timer-based implementation that is simple to use in any application and which won't block other activities.</p>
<p>We start this example by including the <a class="el" href="classBlinkLED.html" title="Blink a LED on a digital output pin. ">BlinkLED</a> class and instantiating an object instance:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;BlinkLED.h&gt;</span></div>
<div class="line"></div>
<div class="line"><a class="code" href="classBlinkLED.html">BlinkLED</a> statusBlink(13, 70, 930);</div>
</div><!-- fragment --></p>
<p>In this example we have specified that the LED is on pin D13, the LED should be on for 70 milliseconds, and off for 930 milliseconds. This will cause the status LED to "strobe" once per second. The LED will be initially off for 930 milliseconds after device reset. To start with the LED on, use the following initialization code instead:</p>
<div class="fragment"><div class="line"><a class="code" href="classBlinkLED.html">BlinkLED</a> statusBlink(13, 70, 930, <span class="keyword">true</span>);</div>
</div><!-- fragment --><p>The remaining code we need is a call to <a class="el" href="classBlinkLED.html#aeeaf42b94c5392935f00f0f12a58c75e">BlinkLED::loop()</a> every time around the main application loop:</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> loop() {</div>
<div class="line"> statusBlink.loop();</div>
<div class="line">}</div>
</div><!-- fragment --></p>
<p>As can be seen, <a class="el" href="classBlinkLED.html" title="Blink a LED on a digital output pin. ">BlinkLED</a> simplifies the process of blinking a LED quite considerably. It is also possible to <a class="el" href="classBlinkLED.html#a2760a0223cd6a0598b961f681ffb5c0a">pause()</a> and <a class="el" href="classBlinkLED.html#a380241e4dfd20e8a558487227f2f4252">resume()</a> the blinking. This is useful in applications where a blinking LED indicates a certain state such as an error condition or a long-running operation that is in progress; with the LED off at other times. The on/off blink rate can be modified at runtime using <a class="el" href="classBlinkLED.html#a47f95624881063aa91c0066ed2c92258" title="Sets the onTime and offTime (in milliseconds). ">BlinkLED::setBlinkRate()</a>, and the LED can be set to a specific value using <a class="el" href="classBlinkLED.html#af904a345e56d49948a042ac439d0b9d4" title="Sets the current state of the LED, where true is on, false is off. ">BlinkLED::setState()</a>.</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">Blink the status LED using the BlinkLED utility class.</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 &lt;BlinkLED.h&gt;</span></div>
<div class="line"></div>
<div class="line"><a class="code" href="classBlinkLED.html">BlinkLED</a> statusBlink(13, 70, 930);</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> setup() {}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> loop() {</div>
<div class="line"> statusBlink.loop();</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 Sun Feb 18 2018 09:12:22 for ArduinoLibs by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>