The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
CIRC-06 | Music With Piezos Netduino Plus 2 MS Port
If anyone having the same issue, the below is the updated working code for Microsoft.SPOT.Hardware.PWM
using System; //use base classes using System.Threading; //use threading classes using Microsoft.SPOT; //use smart personal objects technology classesusing Microsoft.SPOT.Hardware; //use hardware related SPOT classesusing SecretLabs.NETMF.Hardware; //use Secret Labs hardware frameworkusing SecretLabs.NETMF.Hardware.Netduino; //use the Netduino specific classesnamespace Piezo{ public class Program { //static PWM speaker = new PWM(Pins.GPIO_PIN_D9); // Add the following line instead of this one static PWM speaker = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D9, 100000, 0.5, false); static char[] notes = "ccggaagffeeddc ".ToCharArray(); static int[] beats = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; static int tempo = 300; public static void Main() { speaker.Start(); // Add this while (true) { for (int i = 0; i < notes.Length; i++) { playNote(notes[i], beats[i] * tempo); playNote(' ', tempo / 2); } } } /// <summary> /// Plays a particular tone for a particular duration /// </summary> /// <param name="tone">The tone to play</param> /// <param name="duration">How long to play the tone</param> static void playTone(int tone, int duration) { //speaker.SetPulse((uint)(tone * 2), (uint)tone); //Uncomment this nad use the next two lines instead speaker.Period = (uint)tone * 2; speaker.Duration = (uint)tone; Thread.Sleep(duration); //waits the appropriate amount of time } /// <summary> /// Looks up the tone for a note based on it's letter and plays /// it for a specific amount of time /// </summary> /// <param name="note">The letter of the note to play</param> /// <param name="duration">How long to play the tone</param> static void playNote(char note, int duration) { char[] names = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', ' ' }; //The array of possible notes int[] tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 0 };//The frequency of each note in the previous array for (int i = 0; i < 9; i++) //Goes through each note { if (names[i] == note) { playTone(tones[i], duration); //Plays the right note } } } }}
Edited: to the right Version of the script.
Jean-Martin
using System; //use base classes using System.Threading; //use threading classes using Microsoft.SPOT; //use smart personal objects technology classesusing Microsoft.SPOT.Hardware; //use hardware related SPOT classesusing SecretLabs.NETMF.Hardware; //use Secret Labs hardware frameworkusing SecretLabs.NETMF.Hardware.Netduino; //use the Netduino specific classesnamespace Piezo{ public class Program { //static PWM speaker = new PWM(Pins.GPIO_PIN_D9); // Add the following line instead of this one static PWM speaker = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D9, 100000, 0.5, false); static char[] notes = "ccggaagffeeddc ".ToCharArray(); static int[] beats = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; static int tempo = 300; public static void Main() { speaker.Start(); // Add this while (true) { for (int i = 0; i < notes.Length; i++) { playNote(notes[i], beats[i] * tempo); playNote(' ', tempo / 2); } } } /// <summary> /// Plays a particular tone for a particular duration /// </summary> /// <param name="tone">The tone to play</param> /// <param name="duration">How long to play the tone</param> static void playTone(int tone, int duration) { //speaker.SetPulse((uint)(tone * 2), (uint)tone); //Uncomment this nad use the next two lines instead speaker.Period = (uint)tone * 2; speaker.Duration = (uint)tone; Thread.Sleep(duration); //waits the appropriate amount of time } /// <summary> /// Looks up the tone for a note based on it's letter and plays /// it for a specific amount of time /// </summary> /// <param name="note">The letter of the note to play</param> /// <param name="duration">How long to play the tone</param> static void playNote(char note, int duration) { char[] names = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', ' ' }; //The array of possible notes int[] tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 0 };//The frequency of each note in the previous array for (int i = 0; i < 9; i++) //Goes through each note { if (names[i] == note) { playTone(tones[i], duration); //Plays the right note } } } }}
If anyone having the same issue, the below is the updated working code for Microsoft.SPOT.Hardware.PWM
using System; //use base classes using System.Threading; //use threading classes using Microsoft.SPOT; //use smart personal objects technology classesusing Microsoft.SPOT.Hardware; //use hardware related SPOT classesusing SecretLabs.NETMF.Hardware; //use Secret Labs hardware frameworkusing SecretLabs.NETMF.Hardware.Netduino; //use the Netduino specific classesnamespace Piezo{ public class Program { //static PWM speaker = new PWM(Pins.GPIO_PIN_D9); // Add the following line instead of this one static PWM speaker = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D9, 100000, 0.5, false); static char[] notes = "ccggaagffeeddc ".ToCharArray(); static int[] beats = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; static int tempo = 300; public static void Main() { speaker.Start(); // Add this while (true) { for (int i = 0; i < notes.Length; i++) { playNote(notes[i], beats[i] * tempo); playNote(' ', tempo / 2); } } } /// <summary> /// Plays a particular tone for a particular duration /// </summary> /// <param name="tone">The tone to play</param> /// <param name="duration">How long to play the tone</param> static void playTone(int tone, int duration) { //speaker.SetPulse((uint)(tone * 2), (uint)tone); //Uncomment this nad use the next two lines instead speaker.Period = (uint)tone * 2; speaker.Duration = (uint)tone; Thread.Sleep(duration); //waits the appropriate amount of time } /// <summary> /// Looks up the tone for a note based on it's letter and plays /// it for a specific amount of time /// </summary> /// <param name="note">The letter of the note to play</param> /// <param name="duration">How long to play the tone</param> static void playNote(char note, int duration) { char[] names = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', ' ' }; //The array of possible notes int[] tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 0 };//The frequency of each note in the previous array for (int i = 0; i < 9; i++) //Goes through each note { if (names[i] == note) { playTone(tones[i], duration); //Plays the right note } } } }}
If anyone having the same issue, the below is the updated working code for Microsoft.SPOT.Hardware.PWM
using System; //use base classes using System.Threading; //use threading classes using Microsoft.SPOT; //use smart personal objects technology classesusing Microsoft.SPOT.Hardware; //use hardware related SPOT classesusing SecretLabs.NETMF.Hardware; //use Secret Labs hardware frameworkusing SecretLabs.NETMF.Hardware.Netduino; //use the Netduino specific classesnamespace Piezo{ public class Program { //static PWM speaker = new PWM(Pins.GPIO_PIN_D9); // Add the following line instead of this one static PWM speaker = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D9, 100000, 0.5, false); static char[] notes = "ccggaagffeeddc ".ToCharArray(); static int[] beats = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; static int tempo = 300; public static void Main() { speaker.Start(); // Add this while (true) { for (int i = 0; i < notes.Length; i++) { playNote(notes[i], beats[i] * tempo); playNote(' ', tempo / 2); } } } /// <summary> /// Plays a particular tone for a particular duration /// </summary> /// <param name="tone">The tone to play</param> /// <param name="duration">How long to play the tone</param> static void playTone(int tone, int duration) { //speaker.SetPulse((uint)(tone * 2), (uint)tone); //Uncomment this nad use the next two lines instead speaker.Period = (uint)tone * 2; speaker.Duration = (uint)tone; Thread.Sleep(duration); //waits the appropriate amount of time } /// <summary> /// Looks up the tone for a note based on it's letter and plays /// it for a specific amount of time /// </summary> /// <param name="note">The letter of the note to play</param> /// <param name="duration">How long to play the tone</param> static void playNote(char note, int duration) { char[] names = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', ' ' }; //The array of possible notes int[] tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 0 };//The frequency of each note in the previous array for (int i = 0; i < 9; i++) //Goes through each note { if (names[i] == note) { playTone(tones[i], duration); //Plays the right note } } } }}