Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Threading;
- using NetduinoGo;
- using PWM = Microsoft.SPOT.Hardware.PWM;
- namespace NetduinoGo_ShieldBase
- {
- public class Program
- {
- public static void Main()
- {
- ShieldBase sb = new ShieldBase((GoBus.GoSocket)4);
- PWM speaker = new PWM(sb.PWMChannels.PWM_3, 50, .5, false);
- System.Collections.Hashtable scale = new System.Collections.Hashtable
- {
- {"c", 1915u},
- {"d", 1700u},
- {"e", 1519u},
- {"f", 1432u},
- {"g", 1275u},
- {"a", 1136u},
- {"b", 1014u},
- {"C", 956u},
- {"D", 851u},
- {"E", 758u},
- {"h", 0u}
- };
- int beatsPerMinute = 90;
- int beatTimeInMilliseconds =
- 60000 / beatsPerMinute; // 60,000 milliseconds per minute
- int pauseTimeInMilliseconds = (int)(beatTimeInMilliseconds * 0.1);
- // define the song (letter of note followed by length of note)
- string song = "C1C1C1g1a1a1g2E1E1D1D1C2";
- for (int i = 0; i < song.Length; i += 2)
- {
- // extract each note and its length in beats
- string note = song.Substring(i, 1);
- int beatCount = int.Parse(song.Substring(i + 1, 1));
- uint noteDuration = (uint)scale[note];
- speaker.Duration = noteDuration;
- speaker.Period = noteDuration*2;
- speaker.Start();
- Thread.Sleep(beatTimeInMilliseconds * beatCount - pauseTimeInMilliseconds);
- speaker.Stop();
- Thread.Sleep(pauseTimeInMilliseconds);
- }
- Thread.Sleep(Timeout.Infinite);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment