Example 2 : A whistling kettle with boiling water sound.
This is a full sketch.
// Example for the toneAC library
// A whistling kettle with boiling water sound.
// public domain
#include <toneAC.h>
void setup()
{
}
void loop()
{
int i, freq, freq_extra, freq_shift, vol;
freq = 1440;
vol = 1;
for (i=0; i<1000; i++)
{
freq_shift = random (-15, 15);
freq += freq_shift;
// Stay around the frequency 1440
if (freq < 1440)
freq ++;
else
freq --;
vol = i/50;
if (vol > 10)
vol = 10;
if (i > 800)
freq_extra = (vol * vol) + 800;
else
freq_extra = (vol * vol) + i;
toneAC( freq + freq_extra, vol, 0, true);
delay(30);
}
noToneAC();
delay(5000);
}