コード例 #1
0
        public override void Set(double frequency, double dutyCycle)
        {
            if (frequency < 0)
            {
                throw new ArgumentException("frequency");
            }

            if (dutyCycle < 0 || dutyCycle > 1)
            {
                throw new ArgumentException("dutyCycle");
            }

            if (_port == null)
            {
                _port = new Hardware.PWM(_channel, frequency, dutyCycle, _invert);

                _port.Start();
                _started = true;
            }
            else
            {
                if (_started)
                {
                    _port.Stop();
                }

                _port.Frequency = frequency;
                _port.DutyCycle = dutyCycle;

                _port.Start();
                _started = true;
            }
        }
コード例 #2
0
        private void Move(Direction direction)
        {
            //Debug.Print((!CANifier.GetGeneralInput(forwardLimitSwitch)).ToString() + (!CANifier.GetGeneralInput(reverseLimitSwitch)).ToString());


            if (direction != lastDirection)
            {
                Thread.Sleep(250);
            }

            if (direction == Direction.FORWARDS && IsForwardLimitSwitchPressed())
            {
                Stop();
                //  Debug.Print("Forward Limit Switch Tripped");
                return;
            }
            else if (direction == Direction.BACKWARDS && IsReverseLimitSwitchPressed())
            {
                Stop();
                //  Debug.Print("Reverse Limit Switch Tripped");
                return;
            }

            lastDirection = direction;

            if (direction == Direction.STOPPED)
            {
                movePort.Stop();
                return;
            }

            CANifier.SetGeneralOutput(directionPort, direction == Direction.FORWARDS, true);

            movePort.Start();
        }
コード例 #3
0
        private void PlaySound(uint period, uint duration, int length)
        {
            var pwm = new PWM(_channel, period, duration, PWM.ScaleFactor.Microseconds, false);

            pwm.Start();
            Thread.Sleep(length);
            pwm.Stop();
        }
コード例 #4
0
        public static void Main()
        {
            PWM speaker = new PWM(PWMChannels.PWM_PIN_D5, 2000, 0.95, true);

            // Store the notes on the music scale and their associated pulse lengths
            System.Collections.Hashtable scale = new System.Collections.Hashtable();

            // low octave
            scale.Add("c", 1915u);
            scale.Add("d", 1700u);
            scale.Add("e", 1519u);
            scale.Add("f", 1432u);
            scale.Add("g", 1275u);
            scale.Add("a", 1136u);
            scale.Add("b", 1014u);

            // upper octave
            scale.Add("C", 956u);
            scale.Add("D", 851u);
            scale.Add("E", 758u);
            scale.Add("F", 671u);
            scale.Add("G", 594u);

            // hold note
            scale.Add("H", 0u);

            int beatsPerMinute = 90;
            int beatTimeInMilliseconds = 60000 / beatsPerMinute;
            int pauseTimeInMilliseconds = (int)(beatTimeInMilliseconds * 0.1);

            // Define the song (letter of note followed by length of note)
            string song = "C1C1C1g1a1a1g2E1E1D1D1C2";

            // interpret and play the song
            for (int i = 0; i < song.Length; i += 2)
            {
                //Extract each note and the length in beats
                string note = song.Substring(i, 1);
                int beatCount = int.Parse(song.Substring(i + 1, 1));

                // look up the note duration in milliseconds
                uint noteFrequency = (uint)scale[note];
                int duration = beatCount * beatTimeInMilliseconds;

                // play the note for the desired duration
                speaker.Frequency = noteFrequency;
                Debug.Print(beatCount + "\t" + beatTimeInMilliseconds + "\t" + pauseTimeInMilliseconds + "\t" + duration + "\t"  + speaker.Duration + "\t" + speaker.DutyCycle + "\t" + speaker.Frequency + "\t" + speaker.Period);
                speaker.Start();
                Thread.Sleep(duration);
                speaker.Stop();

                // Pause for 1/10th of one beat
                Thread.Sleep(pauseTimeInMilliseconds);
            }
            Thread.Sleep(Timeout.Infinite);
        }
コード例 #5
0
ファイル: Sound.cs プロジェクト: Joshua312/Netduino-Project
        public static void Main()
        {
            // write your code here
            var 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 = 6000 / beatsPerMinute;
            int pauseTimeInMillisenconds = (int)(beatTimeInMilliseconds * 0.1);

            string song = "C1C1C1g1a1a1g2E1E1D1D1C2";

            PWM speaker = new PWM(PWMChannels.PWM_PIN_D5, 100, .5, false);
            speaker.Start();

            for (int i = 0; i < song.Length; i += 2)
            {
                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);

                Thread.Sleep(beatTimeInMilliseconds * beatCount - pauseTimeInMillisenconds);
                speaker.DutyCycle = 0;
                Thread.Sleep(pauseTimeInMillisenconds);
            }

            speaker.Stop();

            Thread.Sleep(Timeout.Infinite);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: masterhou/webgl2012
 public static void SendBit(PWM infraredOut, OutputPort led, char c)
 {
     if (c == '1')
     {
         var startTime = DateTime.Now;
         infraredOut.Start();
         while (startTime.AddMilliseconds(sleep) > DateTime.Now)
         {
             led.Write(true);
             //noop
         }
         infraredOut.Stop();
     }
     else
     {
         var startTime = DateTime.Now;
         while (startTime.AddMilliseconds(sleep) > DateTime.Now)
         {
             led.Write(false);
             //noop
         }
         startTime = DateTime.Now;
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: masterhou/webgl2012
        public static void SendBit(PWM infraredOut, char c)
        {
            if (c == '1')
            {
                var startTime = DateTime.Now;
                infraredOut.Start();
                while (startTime.AddMilliseconds(sleep) > DateTime.Now)
                {

                }
                infraredOut.Stop();
            }
            else
            {
                var startTime = DateTime.Now;
                while (startTime.AddMilliseconds(sleep) > DateTime.Now)
                {

                }
                startTime = DateTime.Now;
            }
        }
コード例 #8
0
        //public void RotateTo(int angle, double speed)
        //{
        //}

        /// <summary>
        /// Stops the signal that controls the servo angle. For many servos, this will
        /// return the servo to its nuetral position (usually 0º).
        /// </summary>
        public void Stop()
        {
            _pwm.Stop();
            _angle = -1;
        }
コード例 #9
0
        public static void Main()
        {
            var songs = new[]
                            {
                                "The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6"
                                ,
                                "Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6"
                                ,
                                "TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5"
                                ,
                                "Entertainer:d=4,o=5,b=140:8d,8d#,8e,c6,8e,c6,8e,2c.6,8c6,8d6,8d#6,8e6,8c6,8d6,e6,8b,d6,2c6,p,8d,8d#,8e,c6,8e,c6,8e,2c.6,8p,8a,8g,8f#,8a,8c6,e6,8d6,8c6,8a,2d6"
                                ,
                                "Muppets:d=4,o=5,b=250:c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,8a,8p,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,8e,8p,8e,g,2p,c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,a,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,d,8d,c"
                                ,
                                "Xfiles:d=4,o=5,b=125:e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,g6,f#6,e6,d6,e6,2b.,1p,g6,f#6,e6,d6,f#6,2b.,1p,e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,e6,2b."
                                ,
                                "Looney:d=4,o=5,b=140:32p,c6,8f6,8e6,8d6,8c6,a.,8c6,8f6,8e6,8d6,8d#6,e.6,8e6,8e6,8c6,8d6,8c6,8e6,8c6,8d6,8a,8c6,8g,8a#,8a,8f"
                                ,
                                "20thCenFox:d=16,o=5,b=140:b,8p,b,b,2b,p,c6,32p,b,32p,c6,32p,b,32p,c6,32p,b,8p,b,b,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,g#,32p,a,32p,b,8p,b,b,2b,4p,8e,8g#,8b,1c#6,8f#,8a,8c#6,1e6,8a,8c#6,8e6,1e6,8b,8g#,8a,2b"
                                ,
                                "Bond:d=4,o=5,b=80:32p,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d#6,16d#6,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d6,16c#6,16c#7,c.7,16g#6,16f#6,g#.6"
                                ,
                                "MASH:d=8,o=5,b=140:4a,4g,f#,g,p,f#,p,g,p,f#,p,2e.,p,f#,e,4f#,e,f#,p,e,p,4d.,p,f#,4e,d,e,p,d,p,e,p,d,p,2c#.,p,d,c#,4d,c#,d,p,e,p,4f#,p,a,p,4b,a,b,p,a,p,b,p,2a.,4p,a,b,a,4b,a,b,p,2a.,a,4f#,a,b,p,d6,p,4e.6,d6,b,p,a,p,2b"
                                ,
                                "StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6"
                                ,
                                "GoodBad:d=4,o=5,b=56:32p,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,d#,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,c#6,32a#,32d#6,32a#,32d#6,8a#.,16f#.,32f.,32d#.,c#,32a#,32d#6,32a#,32d#6,8a#.,16g#.,d#"
                                ,
                                "TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#"
                                ,
                                "A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#"
                                ,
                                "Flinstones:d=4,o=5,b=40:32p,16f6,16a#,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,d6,16f6,16a#.,16a#6,32g6,16f6,16a#.,32f6,32f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,a#,16a6,16d.6,16a#6,32a6,32a6,32g6,32f#6,32a6,8g6,16g6,16c.6,32a6,32a6,32g6,32g6,32f6,32e6,32g6,8f6,16f6,16a#.,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#6,16c7,8a#.6"
                                ,
                                "Jeopardy:d=4,o=6,b=125:c,f,c,f5,c,f,2c,c,f,c,f,a.,8g,8f,8e,8d,8c#,c,f,c,f5,c,f,2c,f.,8d,c,a#5,a5,g5,f5,p,d#,g#,d#,g#5,d#,g#,2d#,d#,g#,d#,g#,c.7,8a#,8g#,8g,8f,8e,d#,g#,d#,g#5,d#,g#,2d#,g#.,8f,d#,c#,c,p,a#5,p,g#.5,d#,g#"
                                ,
                                "Gadget:d=16,o=5,b=50:32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,32d#,32f,32f#,32g#,a#,d#6,4d6,32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,8d#"
                                ,
                                "Smurfs:d=32,o=5,b=200:4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8f#,p,8a#,p,4g#,4p,g#,p,a#,p,b,p,c6,p,4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8b,p,8f,p,4f#"
                                ,
                                "MahnaMahna:d=16,o=6,b=125:c#,c.,b5,8a#.5,8f.,4g#,a#,g.,4d#,8p,c#,c.,b5,8a#.5,8f.,g#.,8a#.,4g,8p,c#,c.,b5,8a#.5,8f.,4g#,f,g.,8d#.,f,g.,8d#.,f,8g,8d#.,f,8g,d#,8c,a#5,8d#.,8d#.,4d#,8d#."
                                ,
                                "LeisureSuit:d=16,o=6,b=56:f.5,f#.5,g.5,g#5,32a#5,f5,g#.5,a#.5,32f5,g#5,32a#5,g#5,8c#.,a#5,32c#,a5,a#.5,c#.,32a5,a#5,32c#,d#,8e,c#.,f.,f.,f.,f.,f,32e,d#,8d,a#.5,e,32f,e,32f,c#,d#.,c#"
                                ,
                                "MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d"
                                ,
                                "axelf2:d=4,o=5,b=125:e,8g.,8e,16e,8a,8e,8d,e,8b.,8e,16e,8c6,8b,8g,8e,8b,8e6,16e,8d,16d,8b4,8f#,e,2p,e,8g.,8e,16e,8a,8e,8d,e,8b.,8e,16e,8c6,8b,8g,8e,8b,8e6,16e,8d,16d,8b4,8f#,e"
                                ,
                                "StWars:d=4,o=5,b=160:8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8d#6,2c6,p,8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8d#6,2c6"
                                ,
                                "PacMan:d=4,o=5,b=90:32b,32p,32b6,32p,32f#6,32p,32d#6,32p,32b6,32f#6,16p,16d#6,16p,32c6,32p,32c7,32p,32g6,32p,32e6,32p,32c7,32g6,16p,16e6,16p,32b,32p,32b6,32p,32f#6,32p,32d#6,32p,32b6,32f#6,16p,16d#6,16p,32d#6,32e6,32f6,32p,32f6,32f#6,32g6,32p,32g6,32g#6,32a6,32p,32b.6"
                            };

            var pwm = new PWM(Cpu.PWMChannel.PWM_4, 50, 0, false);
            var player = new RttlPlayer(new PwmSpeaker(pwm));

            foreach (string song in songs)
                player.Play(song);

            pwm.Stop();
        }
コード例 #10
0
 /// <summary>
 /// Stops rotation of the servo.
 /// </summary>
 public void Stop()
 {
     _pwm.Stop();
     _currentDirection = RotationDirection.None;
     _currentSpeed     = 0.0f;
 }