1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/classMelody.html
Rhys Weatherley 17f4fb4873 Update docs
2012-06-18 11:03:07 +10:00

351 lines
22 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: Melody 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> </div>
<div class="headertitle">
<div class="title">Melody Class Reference</div> </div>
</div>
<div class="contents">
<!-- doxytag: class="Melody" -->
<p>Plays a melody on a digital output pin using tone().
<a href="classMelody.html#details">More...</a></p>
<p><code>#include &lt;<a class="el" href="Melody_8h_source.html">Melody.h</a>&gt;</code></p>
<p><a href="classMelody-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"><a class="anchor" id="a9edc4165a49368dd5d78eedf982c38b9"></a><!-- doxytag: member="Melody::Melody" ref="a9edc4165a49368dd5d78eedf982c38b9" args="(uint8_t pin)" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#a9edc4165a49368dd5d78eedf982c38b9">Melody</a> (uint8_t pin)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a new melody playing object for <em>pin</em>. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ad38db3338ed87d72238c0ea9440c633c"></a><!-- doxytag: member="Melody::isPlaying" ref="ad38db3338ed87d72238c0ea9440c633c" args="() const " -->
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#ad38db3338ed87d72238c0ea9440c633c">isPlaying</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns true if the melody is currently playing; false if not. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#ab78253ae9abc8478b05f415f5d878a60">loopCount</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the number of times the melody should loop before stopping. <a href="#ab78253ae9abc8478b05f415f5d878a60"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#a507097a2e8ff51a5e9157e3a320ae35b">setLoopCount</a> (int count)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets the number of times the melody should loop to <em>count</em>. <a href="#a507097a2e8ff51a5e9157e3a320ae35b"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#ae88ad06c2acb728f56dd213d5dad6006">setLoopDuration</a> (unsigned long ms)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets the maximum number of loops to last no longer than <em>ms</em> milliseconds. <a href="#ae88ad06c2acb728f56dd213d5dad6006"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#a9fd8e0d48833d8da3cd3b3b58408b0b5">play</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Starts playing the melody, or restarts it if already playing. <a href="#a9fd8e0d48833d8da3cd3b3b58408b0b5"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#aecc9185c9cb1246e8a55521b17d72932">playOnce</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Plays the melody once and then stops. <a href="#aecc9185c9cb1246e8a55521b17d72932"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#ac0c552233c41d85f2766d2e4df376b2b">stop</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Stops playing the melody. <a href="#ac0c552233c41d85f2766d2e4df376b2b"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#adb6ad8e8cfe8c9a137e470f4e85c7254">setMelody</a> (const int *notes, const uint8_t *lengths, unsigned int size)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets the melody to the <em>size</em> elements of <em>notes</em> and <em>lengths</em>. <a href="#adb6ad8e8cfe8c9a137e470f4e85c7254"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMelody.html#ad1103b970be1f59058cc7d927be68955">run</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Runs the melody control loop. <a href="#ad1103b970be1f59058cc7d927be68955"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Plays a melody on a digital output pin using tone(). </p>
<p>The following example plays a simple tone three times on digital pin 8:</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;Melody.h&gt;</span>
<span class="keywordtype">int</span> notes[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3,
NOTE_REST, NOTE_B3, NOTE_C4, NOTE_REST
};
byte lengths[] = {4, 8, 8, 4, 4, 4, 4, 4, 2};
<a class="code" href="classMelody.html" title="Plays a melody on a digital output pin using tone().">Melody</a> melody(8);
<span class="keywordtype">void</span> setup() {
melody.setMelody(notes, lengths, <span class="keyword">sizeof</span>(lengths));
melody.setLoopCount(3);
melody.play();
}
<span class="keywordtype">void</span> loop() {
melody.run();
}
</pre></div><p>The <code>notes</code> array contains the frequency of the notes to be played, with the special value <code>NOTE_REST</code> indicating a rest where no notes are playing. The <code>lengths</code> array contains the lengths of each of the notes; a value of 4 indicates a quarter note, a value of 8 indicates an eighth note, etc.</p>
<p>The <a class="el" href="classMelody.html#ad1103b970be1f59058cc7d927be68955" title="Runs the melody control loop.">run()</a> method must be called from the application's main <code>loop()</code> method to ensure that the melody advances from one note to the next. It will not block the application while notes are playing.</p>
<p>The number of loops can also be specified with <a class="el" href="classMelody.html#ae88ad06c2acb728f56dd213d5dad6006" title="Sets the maximum number of loops to last no longer than ms milliseconds.">setLoopDuration()</a> which sets a maximum amount of time that the melody will play before stopping. The following example plays the melody for no more than 60 seconds:</p>
<div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> setup() {
melody.setMelody(notes, lengths, <span class="keyword">sizeof</span>(lengths));
melody.setLoopDuration(60000UL);
melody.play();
}
</pre></div>
<p>Definition at line <a class="el" href="Melody_8h_source.html#l00122">122</a> of file <a class="el" href="Melody_8h_source.html">Melody.h</a>.</p>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="ab78253ae9abc8478b05f415f5d878a60"></a><!-- doxytag: member="Melody::loopCount" ref="ab78253ae9abc8478b05f415f5d878a60" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int Melody::loopCount </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 times the melody should loop before stopping. </p>
<p>The default value is zero, indicating that the melody will loop indefinitely.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#a507097a2e8ff51a5e9157e3a320ae35b" title="Sets the number of times the melody should loop to count.">setLoopCount()</a>, <a class="el" href="classMelody.html#ae88ad06c2acb728f56dd213d5dad6006" title="Sets the maximum number of loops to last no longer than ms milliseconds.">setLoopDuration()</a>, <a class="el" href="classMelody.html#a9fd8e0d48833d8da3cd3b3b58408b0b5" title="Starts playing the melody, or restarts it if already playing.">play()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8h_source.html#l00128">128</a> of file <a class="el" href="Melody_8h_source.html">Melody.h</a>.</p>
</div>
</div>
<a class="anchor" id="a9fd8e0d48833d8da3cd3b3b58408b0b5"></a><!-- doxytag: member="Melody::play" ref="a9fd8e0d48833d8da3cd3b3b58408b0b5" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::play </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Starts playing the melody, or restarts it if already playing. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#aecc9185c9cb1246e8a55521b17d72932" title="Plays the melody once and then stops.">playOnce()</a>, <a class="el" href="classMelody.html#adb6ad8e8cfe8c9a137e470f4e85c7254" title="Sets the melody to the size elements of notes and lengths.">setMelody()</a>, <a class="el" href="classMelody.html#ac0c552233c41d85f2766d2e4df376b2b" title="Stops playing the melody.">stop()</a>, <a class="el" href="classMelody.html#ab78253ae9abc8478b05f415f5d878a60" title="Returns the number of times the melody should loop before stopping.">loopCount()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8cpp_source.html#l00146">146</a> of file <a class="el" href="Melody_8cpp_source.html">Melody.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="aecc9185c9cb1246e8a55521b17d72932"></a><!-- doxytag: member="Melody::playOnce" ref="aecc9185c9cb1246e8a55521b17d72932" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::playOnce </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Plays the melody once and then stops. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#a9fd8e0d48833d8da3cd3b3b58408b0b5" title="Starts playing the melody, or restarts it if already playing.">play()</a>, <a class="el" href="classMelody.html#ac0c552233c41d85f2766d2e4df376b2b" title="Stops playing the melody.">stop()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8cpp_source.html#l00162">162</a> of file <a class="el" href="Melody_8cpp_source.html">Melody.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="ad1103b970be1f59058cc7d927be68955"></a><!-- doxytag: member="Melody::run" ref="ad1103b970be1f59058cc7d927be68955" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::run </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Runs the melody control loop. </p>
<p>This function must be called by the application's main <code>loop()</code> function to cause the melody to advance from note to note. It will not block the application while notes are playing. </p>
<p>Definition at line <a class="el" href="Melody_8cpp_source.html#l00214">214</a> of file <a class="el" href="Melody_8cpp_source.html">Melody.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="a507097a2e8ff51a5e9157e3a320ae35b"></a><!-- doxytag: member="Melody::setLoopCount" ref="a507097a2e8ff51a5e9157e3a320ae35b" args="(int count)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::setLoopCount </td>
<td>(</td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>count</em></td><td>)</td>
<td><code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Sets the number of times the melody should loop to <em>count</em>. </p>
<p>If <em>count</em> is zero, then the melody will loop indefinitely.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#ab78253ae9abc8478b05f415f5d878a60" title="Returns the number of times the melody should loop before stopping.">loopCount()</a>, <a class="el" href="classMelody.html#ae88ad06c2acb728f56dd213d5dad6006" title="Sets the maximum number of loops to last no longer than ms milliseconds.">setLoopDuration()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8h_source.html#l00129">129</a> of file <a class="el" href="Melody_8h_source.html">Melody.h</a>.</p>
</div>
</div>
<a class="anchor" id="ae88ad06c2acb728f56dd213d5dad6006"></a><!-- doxytag: member="Melody::setLoopDuration" ref="ae88ad06c2acb728f56dd213d5dad6006" args="(unsigned long ms)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::setLoopDuration </td>
<td>(</td>
<td class="paramtype">unsigned long&#160;</td>
<td class="paramname"><em>ms</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Sets the maximum number of loops to last no longer than <em>ms</em> milliseconds. </p>
<p>This function must be called after the melody is specified with <a class="el" href="classMelody.html#adb6ad8e8cfe8c9a137e470f4e85c7254" title="Sets the melody to the size elements of notes and lengths.">setMelody()</a> as it uses the length of the melody and <em>ms</em> to determine the <a class="el" href="classMelody.html#ab78253ae9abc8478b05f415f5d878a60" title="Returns the number of times the melody should loop before stopping.">loopCount()</a>.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#ab78253ae9abc8478b05f415f5d878a60" title="Returns the number of times the melody should loop before stopping.">loopCount()</a>, <a class="el" href="classMelody.html#a507097a2e8ff51a5e9157e3a320ae35b" title="Sets the number of times the melody should loop to count.">setLoopCount()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8cpp_source.html#l00131">131</a> of file <a class="el" href="Melody_8cpp_source.html">Melody.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="adb6ad8e8cfe8c9a137e470f4e85c7254"></a><!-- doxytag: member="Melody::setMelody" ref="adb6ad8e8cfe8c9a137e470f4e85c7254" args="(const int *notes, const uint8_t *lengths, unsigned int size)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::setMelody </td>
<td>(</td>
<td class="paramtype">const int *&#160;</td>
<td class="paramname"><em>notes</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const uint8_t *&#160;</td>
<td class="paramname"><em>lengths</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">unsigned int&#160;</td>
<td class="paramname"><em>size</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Sets the melody to the <em>size</em> elements of <em>notes</em> and <em>lengths</em>. </p>
<p>If a melody is currently playing, then this function will stop playback.</p>
<p>The <em>notes</em> array contains the frequency of the notes to be played, with the special value <code>NOTE_REST</code> indicating a rest where no notes are playing. The <em>lengths</em> array contains the lengths of each of the notes; a value of 4 indicates a quarter note, a value of 8 indicates an eighth note, etc.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#a9fd8e0d48833d8da3cd3b3b58408b0b5" title="Starts playing the melody, or restarts it if already playing.">play()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8cpp_source.html#l00199">199</a> of file <a class="el" href="Melody_8cpp_source.html">Melody.cpp</a>.</p>
</div>
</div>
<a class="anchor" id="ac0c552233c41d85f2766d2e4df376b2b"></a><!-- doxytag: member="Melody::stop" ref="ac0c552233c41d85f2766d2e4df376b2b" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Melody::stop </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Stops playing the melody. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classMelody.html#a9fd8e0d48833d8da3cd3b3b58408b0b5" title="Starts playing the melody, or restarts it if already playing.">play()</a> </dd></dl>
<p>Definition at line <a class="el" href="Melody_8cpp_source.html#l00178">178</a> of file <a class="el" href="Melody_8cpp_source.html">Melody.cpp</a>.</p>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="Melody_8h_source.html">Melody.h</a></li>
<li><a class="el" href="Melody_8cpp_source.html">Melody.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 Mon Jun 18 2012 11:02:53 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>