Hello Tunes Module

Recently I had a look at the gadgeteer LED strip module. This post is about the gadgeteer Tunes module. The tunes module is a rather crude sound generator. It can generate one track only and there is no control of the wave shape, but it is still good enough simple melodies or - better - an alarm sound.

The Code

public partial class Program
{
    // This method is run when the mainboard is powered up or reset.   
    void ProgramStarted()
    {
        // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
        Debug.Print("Program Started");
        tunes.AddNote(new Tunes.MusicNote(new Tunes.Tone(440), 500 ));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.C4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.D4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.E4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.F4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.G4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.A4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.B4, 500));
        tunes.AddNote(new Tunes.MusicNote(Tunes.Tone.C5, 500));
        tunes.Play();
    }
}

The tunes module is used but adding notes (MusicNote's) to a queue - let's call it a melody - and then playing the melody with Tunes.Play(). It is also possible to stop the melody from playing further with Tunes.Stop().

The MusicNote takes a Tone and a duration argument. It is very not clear from the documentation, but the duration is given in milliseconds.

The full solution is as usual on my github page.

The Result

The result is a 440 Hz tone (same as A4 actually) and followed by a C major scale.

This is a video where you can hear what is sound like: