Main Site Documentation

Tunes module


#1

Does anybody have any sample code for this module? VB or C#?

Thanks

Sue


#2

Yes I tried that and thought I could just use tunes.SetTone(frequency) and then tunes.Play() but it seems more complicated than that - SetTone() doesn’t come up as an option although listed as a method. I tried the AddNote method but you need to pass in a Tone and that didn’t seem to work either.

Perhaps I’m being a bit dim :frowning: but if anybody had some sample code to get me started it would be great. I work with Gadgeteer in schools.

Sue


#3

Try this to help get started. It should just play a simple scale.

        void ProgramStarted()
        {
            Tunes.MusicNote note = new Tunes.MusicNote(Tunes.Tone.C4, 400);

            tunes.AddNote(note);

            // up
            PlayNote(Tunes.Tone.C4);
            PlayNote(Tunes.Tone.D4);
            PlayNote(Tunes.Tone.E4);
            PlayNote(Tunes.Tone.F4);
            PlayNote(Tunes.Tone.G4);
            PlayNote(Tunes.Tone.A4);
            PlayNote(Tunes.Tone.B4);
            PlayNote(Tunes.Tone.C5);

            // back down
            PlayNote(Tunes.Tone.B4);
            PlayNote(Tunes.Tone.A4);
            PlayNote(Tunes.Tone.G4);
            PlayNote(Tunes.Tone.F4);
            PlayNote(Tunes.Tone.E4);
            PlayNote(Tunes.Tone.D4);
            PlayNote(Tunes.Tone.C4);

            // arpeggio
            PlayNote(Tunes.Tone.E4);
            PlayNote(Tunes.Tone.G4);
            PlayNote(Tunes.Tone.C5);
            PlayNote(Tunes.Tone.G4);
            PlayNote(Tunes.Tone.E4);
            PlayNote(Tunes.Tone.C4);
            
            tunes.Play();

            Thread.Sleep(100);

            PlayNote(Tunes.Tone.E4);
            PlayNote(Tunes.Tone.G4);
            PlayNote(Tunes.Tone.C5);
            PlayNote(Tunes.Tone.G4);
            PlayNote(Tunes.Tone.E4);
            PlayNote(Tunes.Tone.C4);

            tunes.Play();

            Debug.Print("Program Started");
        }

        void PlayNote(Tunes.Tone tone)
        {
            Tunes.MusicNote note = new Tunes.MusicNote(tone, 200);

            tunes.AddNote(note);
        }


#4

That’s great Steven - just what I needed - thanks!
Sue