<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: tone generation code</title>
		<link>http://forums.leaflabs.com/topic.php?id=195</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:19:33 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=195" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1390</link>
			<pubDate>Thu, 23 Sep 2010 13:43:25 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">1390@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Awesome.  Just put this on my github watch list as well.&#60;/p&#62;
&#60;p&#62;High up on our to-do list post Maker faire is a nice way to organize and distribute the community libraries that are starting to spring up.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>wilsonjc on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1387</link>
			<pubDate>Thu, 23 Sep 2010 11:37:59 +0000</pubDate>
			<dc:creator>wilsonjc</dc:creator>
			<guid isPermaLink="false">1387@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I didn't notice that the LED was on that pin.   that probably explains why the audio is a little lower than I expected.   thanks.      I send the audio to a computer amplifier I had lying around so the lower level wasn't that noticeable.   When I am finished I will use headphones on the sound output, but I may have to include a small amplifier.   What I will probably use is a single transistor driven by the micro through a resistor switching the 5V supply. with another resistor in line to limit the current output to the speakers.    That may work for the piezo/buzzer/speaker you want to use.    Adding a simple filter may improve the sound as well.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>leaflabsandy on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1385</link>
			<pubDate>Wed, 22 Sep 2010 20:10:55 +0000</pubDate>
			<dc:creator>leaflabsandy</dc:creator>
			<guid isPermaLink="false">1385@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Nice piece of code.&#60;/p&#62;
&#60;p&#62;I have also noticed that you are using pin 13 as the speaker output. This pin is also used for the blue on board status LED. Just curious, any particular reason why you chose that pin?&#60;/p&#62;
&#60;p&#62;Finding a piezo/buzzer/speaker to work and output a proper sound level at 3.3 VDC&#60;br /&#62;
is extremely hard. You probably need to connect to a higher voltage other than 3.3 VDC.&#60;br /&#62;
I went through a least 4 piezos at 3.3 v and finally switched to connecting the + to&#60;br /&#62;
Vin (+5 VDC) to give it the proper sound output. Do you have any better suggestions?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>wilsonjc on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1383</link>
			<pubDate>Wed, 22 Sep 2010 19:46:39 +0000</pubDate>
			<dc:creator>wilsonjc</dc:creator>
			<guid isPermaLink="false">1383@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ok I hope i did this git thing right.   If I did, you should find the source files for the sound program here....&#60;br /&#62;
&#60;a href=&#34;http://github.com/wilsonjc/Maple_Sound/&#34; rel=&#34;nofollow&#34;&#62;http://github.com/wilsonjc/Maple_Sound/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>wilsonjc on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1348</link>
			<pubDate>Mon, 20 Sep 2010 08:15:26 +0000</pubDate>
			<dc:creator>wilsonjc</dc:creator>
			<guid isPermaLink="false">1348@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Cool! I look forward to your blog post, but for my application a simple tone should be enough.   That is until the guy I am making this for finds out that we can make better sounds with your code, and then the requirements will change. :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1347</link>
			<pubDate>Sun, 19 Sep 2010 20:37:40 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">1347@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;This is where it starts to get fun. Ill be putting up a blog post on this subject soon! Check out what i made last week with Maple - 20 simultaneous sawtooth waves at 50KHz with 16bit PWM (yes i realize the 16 bit pwm is surprise...its actually 2 8 bit pwms combined in a two bit resistor dac!)&#60;/p&#62;
&#60;p&#62;Keep it up!&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/2010/09/oof-out-of-stock/maple_deep_note/&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/2010/09/oof-out-of-stock/maple_deep_note/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>wilsonjc on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1346</link>
			<pubDate>Sun, 19 Sep 2010 20:24:13 +0000</pubDate>
			<dc:creator>wilsonjc</dc:creator>
			<guid isPermaLink="false">1346@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;There is a single error i saw after posting the play=false; at the end of the main program should be&#60;br /&#62;
play=true;&#60;/p&#62;
&#60;p&#62;cheers.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>wilsonjc on "tone generation code"</title>
			<link>http://forums.leaflabs.com/topic.php?id=195#post-1345</link>
			<pubDate>Sun, 19 Sep 2010 20:21:11 +0000</pubDate>
			<dc:creator>wilsonjc</dc:creator>
			<guid isPermaLink="false">1345@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;here is the tone generation code I am using in a larger program.   I clipped it out and changed it a little, and i was unable to test it in this modified form but it runs well in my program.  ...&#60;/p&#62;
&#60;p&#62;Any on can use this for fun or profit :)&#60;br /&#62;
cheers&#60;/p&#62;
&#60;p&#62;ps.  I will add this to github.com as soon as I figure out how to add a repository. :)&#60;/p&#62;
&#60;p&#62;/*&#60;br /&#62;
 *************************&#60;br /&#62;
 * Created 9 Aug. 2010   *&#60;br /&#62;
 * by James Wilson       *&#60;br /&#62;
 *                       *&#60;br /&#62;
 *************************&#60;br /&#62;
 _______________________________________&#60;br /&#62;
 */&#60;/p&#62;
&#60;p&#62;// ************************************************************************&#60;br /&#62;
//    Sound generator&#60;br /&#62;
//*******************************************************&#60;/p&#62;
&#60;p&#62;//   this will generate a square wave at a given frequency on the pin&#60;br /&#62;
//   defined by the &#34;SPEAKER_PIN&#34; definition.   I used Timer number 2 but&#60;br /&#62;
//  if you need to you can change that as well.&#60;br /&#62;
//   cheers.&#60;/p&#62;
&#60;p&#62;//   I clipped this from a working program and modified it a little so&#60;br /&#62;
//   if you have any problems with it let me know.&#60;/p&#62;
&#60;p&#62;//  use : enter in a frequency in to playTone(int playfreq)&#60;br /&#62;
//        and turn the tone on or off with SoundGen( {true / false} );&#60;/p&#62;
&#60;p&#62;//    &#60;/p&#62;
&#60;p&#62;#include &#38;lt;stdlib.h&#38;gt;&#60;/p&#62;
&#60;p&#62;void SoundGen (int soundOn);&#60;br /&#62;
void playTone(int playfreq);&#60;br /&#62;
void handler_speaker(void); &#60;/p&#62;
&#60;p&#62;#define SPEAKER_PIN  13    // you can change this if you want this is the pin that the sound comes out.&#60;/p&#62;
&#60;p&#62;#define SOUND_PERIOD  2000  // Start period for the sound in microseconds  this is just a test frequency.&#60;br /&#62;
                            // this frequency is used if none is set in playtone()&#60;/p&#62;
&#60;p&#62;byte toggle = 0;           // the present state of the speaker pin&#60;/p&#62;
&#60;p&#62;void setup()&#60;br /&#62;
{&#60;/p&#62;
&#60;p&#62;  // Set up the speaker to make a tone&#60;br /&#62;
  pinMode(SPEAKER_PIN, OUTPUT);&#60;/p&#62;
&#60;p&#62;  // Setup Timer&#60;br /&#62;
  Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);&#60;br /&#62;
  Timer2.setPeriod(SOUND_PERIOD);                            // in microseconds&#60;br /&#62;
  Timer2.setCompare1(1);                                     // overflow might be small&#60;br /&#62;
  Timer2.attachCompare1Interrupt(handler_speaker);&#60;br /&#62;
  Timer2.pause();&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&#60;br /&#62;
//   MAIN program&#60;/p&#62;
&#60;p&#62;// Main program&#60;br /&#62;
int play=false;&#60;br /&#62;
void loop(){&#60;/p&#62;
&#60;p&#62;   if (play = false) {   // only want to start playing the sound once&#60;br /&#62;
     playTone(1000);    //enter frequiency here&#60;br /&#62;
     SoundGen(true);    // turn it on or off here&#60;br /&#62;
   }&#60;/p&#62;
&#60;p&#62;   play=false;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;//************************************************************************&#60;br /&#62;
// Turn sound generator on or off&#60;br /&#62;
//************************************************************************&#60;/p&#62;
&#60;p&#62;void SoundGen (int soundOn){&#60;br /&#62;
  if (soundOn)    // turn the sound on or off&#60;br /&#62;
  {&#60;br /&#62;
    Timer2.resume();&#60;br /&#62;
    //SerialUSB.println(&#34;SoundOn&#34;);&#60;br /&#62;
  }&#60;br /&#62;
  else&#60;br /&#62;
  {&#60;br /&#62;
    Timer2.pause();&#60;br /&#62;
  }&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;//************************************************************************&#60;br /&#62;
// The playTone command&#60;br /&#62;
// Possible change here&#60;br /&#62;
//   incorporate a duration value&#60;br /&#62;
//************************************************************************&#60;br /&#62;
void playTone(int playfreq){&#60;br /&#62;
  char freq[6];&#60;/p&#62;
&#60;p&#62;  playfreq = 1000000/playfreq;    //change it to period&#60;/p&#62;
&#60;p&#62;  Timer2.setPeriod(playfreq);&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;//************************************************************************&#60;br /&#62;
//  interrupt handler for speaker&#60;br /&#62;
//************************************************************************&#60;br /&#62;
void handler_speaker(void) {&#60;/p&#62;
&#60;p&#62;  toggle ^= 1;&#60;br /&#62;
  digitalWrite(SPEAKER_PIN, toggle);&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
