1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/classChaseLEDs.html
Rhys Weatherley 448ca56a5a Update docs
2012-06-10 10:52:14 +10:00

312 lines
19 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: ChaseLEDs Class Reference</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&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li class="current"><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 id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="annotated.html"><span>Class&#160;List</span></a></li>
<li><a href="classes.html"><span>Class&#160;Index</span></a></li>
<li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class&#160;Members</span></a></li>
</ul>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> </div>
<div class="headertitle">
<div class="title">ChaseLEDs Class Reference</div> </div>
</div>
<div class="contents">
<!-- doxytag: class="ChaseLEDs" -->
<p>Chase LED's on output pins in a defined sequence.
<a href="classChaseLEDs.html#details">More...</a></p>
<p><code>#include &lt;<a class="el" href="ChaseLEDs_8h_source.html">ChaseLEDs.h</a>&gt;</code></p>
<p><a href="classChaseLEDs-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classChaseLEDs.html#ab6bb3da371d3730a6552e93a9b2eab78">ChaseLEDs</a> (const uint8_t *pins, int num, unsigned long advanceTime)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Initializes the LED chaser. <a href="#ab6bb3da371d3730a6552e93a9b2eab78"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classChaseLEDs.html#a8745fa6b9f33b6c6274a563dd4dea786">loop</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned long&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classChaseLEDs.html#aed060c51bb63dd8065be89f895989700">advanceTime</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the number of milliseconds that each LED will be lit in the chase sequence. <a href="#aed060c51bb63dd8065be89f895989700"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classChaseLEDs.html#af560270f72302c19fb7f95002089c9d7">setAdvanceTime</a> (unsigned long advanceTime)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets the number of milliseconds to advance between LED's to <em>advanceTime</em>. <a href="#af560270f72302c19fb7f95002089c9d7"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b">advance</a> (uint8_t prevPin, uint8_t nextPin)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Advances to the next LED in sequence, turning off <em>prevPin</em>, and turning on <em>nextPin</em>. <a href="#aa0f4e0bd07dd65ee5574e894a612486b"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classChaseLEDs.html#a27c460fcb341c2dc2fcf9341616eb525">previousPin</a> (int n) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the pin that is <em>n</em> steps back in the sequence. <a href="#a27c460fcb341c2dc2fcf9341616eb525"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Chase LED's on output pins in a defined sequence. </p>
<p>The following example performs a LED chase over the 6 PWM outputs on the Arduino Uno, with a 150 millisecond delay between each LED:</p>
<div class="fragment"><pre class="fragment"> uint8_t pins[] = {3, 5, 6, 9, 10, 11};
<a class="code" href="classChaseLEDs.html" title="Chase LED&#39;s on output pins in a defined sequence.">ChaseLEDs</a> chaser(pins, <span class="keyword">sizeof</span>(pins), 150);
<span class="keywordtype">void</span> <a class="code" href="classChaseLEDs.html#a8745fa6b9f33b6c6274a563dd4dea786">loop</a>() {
chaser.loop();
}
</pre></div><p>After pin 11 is lit, the pattern will repeat at pin 3. To cause the chase to oscillate back and forth instead, extend the sequence as follows:</p>
<div class="fragment"><pre class="fragment"> uint8_t pins[] = {3, 5, 6, 9, 10, 11, 10, 9, 6, 5};
<a class="code" href="classChaseLEDs.html" title="Chase LED&#39;s on output pins in a defined sequence.">ChaseLEDs</a> chaser(pins, <span class="keyword">sizeof</span>(pins), 150);
</pre></div><p>See the <a class="el" href="blink_cylon.html">Cylon</a> example for more information on how to use the <a class="el" href="classChaseLEDs.html" title="Chase LED&#39;s on output pins in a defined sequence.">ChaseLEDs</a> class in a practical application. </p>
<p>Definition at line <a class="el" href="ChaseLEDs_8h_source.html#l00028">28</a> of file <a class="el" href="ChaseLEDs_8h_source.html">ChaseLEDs.h</a>.</p>
</div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="ab6bb3da371d3730a6552e93a9b2eab78"></a><!-- doxytag: member="ChaseLEDs::ChaseLEDs" ref="ab6bb3da371d3730a6552e93a9b2eab78" args="(const uint8_t *pins, int num, unsigned long advanceTime)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">ChaseLEDs::ChaseLEDs </td>
<td>(</td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>pins</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>num</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">unsigned long&#160;</td>
<td class="paramname"><em>advanceTime</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Initializes the LED chaser. </p>
<p>The chase sequence consists of <em>num</em> pins, whose names are given by the <em>pins</em> array. Each LED is lit for <em>advanceTime</em> milliseconds before advancing to the next LED.</p>
<p>This constructor configures all of the pins for output and sets their state to be LOW. The first LED will be lit when the program first calls <a class="el" href="classChaseLEDs.html#a8745fa6b9f33b6c6274a563dd4dea786">loop()</a>.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classChaseLEDs.html#a8745fa6b9f33b6c6274a563dd4dea786">loop()</a> </dd></dl>
<p>Definition at line <a class="el" href="ChaseLEDs_8cpp_source.html#l00071">71</a> of file <a class="el" href="ChaseLEDs_8cpp_source.html">ChaseLEDs.cpp</a>.</p>
</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="aa0f4e0bd07dd65ee5574e894a612486b"></a><!-- doxytag: member="ChaseLEDs::advance" ref="aa0f4e0bd07dd65ee5574e894a612486b" args="(uint8_t prevPin, uint8_t nextPin)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void ChaseLEDs::advance </td>
<td>(</td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>prevPin</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>nextPin</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td><code> [protected, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Advances to the next LED in sequence, turning off <em>prevPin</em>, and turning on <em>nextPin</em>. </p>
<p>The default implementation is equivalent to the following code:</p>
<div class="fragment"><pre class="fragment"> digitalWrite(prevPin, LOW);
digitalWrite(nextPin, HIGH);
</pre></div><p>This method may be overridden in subclasses to provide special effects. See the documentation for <a class="el" href="classChaseLEDs.html#a27c460fcb341c2dc2fcf9341616eb525" title="Returns the pin that is n steps back in the sequence.">previousPin()</a> for some example effects.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classChaseLEDs.html#a27c460fcb341c2dc2fcf9341616eb525" title="Returns the pin that is n steps back in the sequence.">previousPin()</a> </dd></dl>
<p>Definition at line <a class="el" href="ChaseLEDs_8cpp_source.html#l00136">136</a> of file <a class="el" href="ChaseLEDs_8cpp_source.html">ChaseLEDs.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="aed060c51bb63dd8065be89f895989700"></a><!-- doxytag: member="ChaseLEDs::advanceTime" ref="aed060c51bb63dd8065be89f895989700" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">unsigned long ChaseLEDs::advanceTime </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const<code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Returns the number of milliseconds that each LED will be lit in the chase sequence. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classChaseLEDs.html#af560270f72302c19fb7f95002089c9d7" title="Sets the number of milliseconds to advance between LED&#39;s to advanceTime.">setAdvanceTime()</a>, <a class="el" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b" title="Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.">advance()</a> </dd></dl>
<p>Definition at line <a class="el" href="ChaseLEDs_8h_source.html#l00035">35</a> of file <a class="el" href="ChaseLEDs_8h_source.html">ChaseLEDs.h</a>.</p>
</div>
</div>
<a class="anchor" id="a8745fa6b9f33b6c6274a563dd4dea786"></a><!-- doxytag: member="ChaseLEDs::loop" ref="a8745fa6b9f33b6c6274a563dd4dea786" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void ChaseLEDs::loop </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Perform a single iteration of the control loop for this LED chaser. </p>
<p>Definition at line <a class="el" href="ChaseLEDs_8cpp_source.html#l00087">87</a> of file <a class="el" href="ChaseLEDs_8cpp_source.html">ChaseLEDs.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="a27c460fcb341c2dc2fcf9341616eb525"></a><!-- doxytag: member="ChaseLEDs::previousPin" ref="a27c460fcb341c2dc2fcf9341616eb525" args="(int n) const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint8_t ChaseLEDs::previousPin </td>
<td>(</td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>n</em></td><td>)</td>
<td> const<code> [inline, protected]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Returns the pin that is <em>n</em> steps back in the sequence. </p>
<p>If <em>n</em> is zero, then the current pin is returned; if <em>n</em> is 1, then the previous pin is returned; and so on.</p>
<p>This function may be called by subclasses in their <a class="el" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b" title="Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.">advance()</a> method to manipulate pins that are further back in the chase sequence than the immediately previous pin.</p>
<p>For example, the following code implements a LED chaser that lights two pins at a time:</p>
<div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> <a class="code" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b" title="Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.">DoubleChaser::advance</a>(uint8_t prevPin, uint8_t nextPin)
{
digitalWrite(<a class="code" href="classChaseLEDs.html#a27c460fcb341c2dc2fcf9341616eb525" title="Returns the pin that is n steps back in the sequence.">previousPin</a>(2), LOW);
digitalWrite(prevPin, HIGH);
digitalWrite(nextPin, HIGH);
}
</pre></div><p>As another exmaple, the following code uses PWM outputs to fade out the previous pin rather than turn it off immediately:</p>
<div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> <a class="code" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b" title="Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.">FadingChaser::advance</a>(uint8_t prevPin, uint8_t nextPin)
{
digitalWrite(<a class="code" href="classChaseLEDs.html#a27c460fcb341c2dc2fcf9341616eb525" title="Returns the pin that is n steps back in the sequence.">previousPin</a>(2), LOW);
analogWrite(prevPin, 32);
digitalWrite(nextPin, HIGH);
}
</pre></div><p>Note: it is possible to retrieve the <em>following</em> pin in sequence using previousPin(-1). This could be used to fade in the LED that follows <em>nextPin</em>.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b" title="Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.">advance()</a> </dd></dl>
<p>Definition at line <a class="el" href="ChaseLEDs_8h_source.html#l00040">40</a> of file <a class="el" href="ChaseLEDs_8h_source.html">ChaseLEDs.h</a>.</p>
</div>
</div>
<a class="anchor" id="af560270f72302c19fb7f95002089c9d7"></a><!-- doxytag: member="ChaseLEDs::setAdvanceTime" ref="af560270f72302c19fb7f95002089c9d7" args="(unsigned long advanceTime)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void ChaseLEDs::setAdvanceTime </td>
<td>(</td>
<td class="paramtype">unsigned long&#160;</td>
<td class="paramname"><em>advanceTime</em></td><td>)</td>
<td><code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Sets the number of milliseconds to advance between LED's to <em>advanceTime</em>. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classChaseLEDs.html#aed060c51bb63dd8065be89f895989700" title="Returns the number of milliseconds that each LED will be lit in the chase sequence.">advanceTime()</a>, <a class="el" href="classChaseLEDs.html#aa0f4e0bd07dd65ee5574e894a612486b" title="Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.">advance()</a> </dd></dl>
<p>Definition at line <a class="el" href="ChaseLEDs_8h_source.html#l00036">36</a> of file <a class="el" href="ChaseLEDs_8h_source.html">ChaseLEDs.h</a>.</p>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="ChaseLEDs_8h_source.html">ChaseLEDs.h</a></li>
<li><a class="el" href="ChaseLEDs_8cpp_source.html">ChaseLEDs.cpp</a></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></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 Sun Jun 10 2012 10:51:57 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>
</html>