Пример #1
0
        int valoreProporzionaleBotola; //Valore proporzionale asseganto alla botola.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Costruttore
        /// </summary>
        /// <param name="pwm1">pwm1</param>
        /// <param name="pwm2">pwm2</param>
        /// <param name="pinApertura">pin perl' apertura</param>
        /// <param name="pinChiusura">pin per la chiusura</param>
        public Botola(FEZ_Pin.PWM pwm1, FEZ_Pin.PWM pwm2, FEZ_Pin.Digital pinApertura, FEZ_Pin.Digital pinChiusura)
        {
            open = new InputPort((Cpu.Pin)pinApertura, true, Port.ResistorMode.PullUp);     //Creazione porta per l' apertura.
            close = new InputPort((Cpu.Pin)pinChiusura, true, Port.ResistorMode.PullUp);    //Creazione porta per la chiusura.
            pwm5 = new PWM((PWM.Pin)pwm1);  //Creazione porta pwm.
            pwm6 = new PWM((PWM.Pin)pwm2);  //Creazione porta pwm.
        }
        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;
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
        static Config()
        {
            Latch = new OutputPort(Pins.GPIO_PIN_D9, false);
            Device = new SPI.Configuration(
                ChipSelect_Port: Pins.GPIO_NONE, // SS-pin                          = slave select, not used
                ChipSelect_ActiveState: false, // SS-pin active state
                ChipSelect_SetupTime: 0, // The setup time for the SS port
                ChipSelect_HoldTime: 0, // The hold time for the SS port
                Clock_IdleState: true, // The idle state of the clock
                Clock_Edge: true, // The sampling clock edge
                Clock_RateKHz: 30000,
                // The SPI clock rate in KHz         ==> enough to start with, let's see how high we can take this later on
                SPI_mod: SPI.SPI_module.SPI1
                // The used SPI bus (refers to a MOSI MISO and SCLK pinset)   => default pins, also the ones used on the pwm shield
                // specifically: sin = 11, (netduino send, tlc in) and sclck = 13
                );
            // better to pass in the pins, and let the ports and pwms be managed insode the device

            Blank = new PWM(Pins.GPIO_PIN_D10);
            Gsclk = new PWM(Pins.GPIO_PIN_D6);

            LayerPorts=new[]
                         {
                             new OutputPort(Pins.GPIO_PIN_D5, false),
                             new OutputPort(Pins.GPIO_PIN_D4, false),
                             new OutputPort(Pins.GPIO_PIN_D3, false),
                             new OutputPort(Pins.GPIO_PIN_D2, false),
                             new OutputPort(Pins.GPIO_PIN_D7, false),
                             new OutputPort(Pins.GPIO_PIN_D8, false)
                         };
            SideLength = 6;
            TlcChannelCount = 112;
        }
Пример #5
0
        public static void Main()
        {
            // write your code here

            int anaIn = 250; // ADC is 12-bit Resolution
            //SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new Microsoft.NETMF.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_4);
            SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4);

            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            //PWM led2 = new PWM(Cpu.PWMChannel.PWM_0, 100, 100, 0);
            PWM servo = new PWM(Cpu.PWMChannel.PWM_0,20000,1500,PWM.ScaleFactor.Microseconds, false);
            servo.Start();

            servo.DutyCycle = 0;
            servo.Duration = (uint)1500;

            while (true)
            {

                double anaRead = pinA4.Read();
                anaIn = (int)anaRead;

                //LED stuff

                //led.Write(true); // turn on the LED
                //Thread.Sleep(anaIn); // sleep for 250ms
                //led.Write(false); // turn off the LED
                //Thread.Sleep(anaIn); // sleep for 250ms

                servo.Duration = (uint)((1000+anaRead));

            }
        }
Пример #6
0
        public static void Main()
        {
            var pwm0 = new PWM(Cpu.PWMChannel.PWM_0, 300, 0, false);
            pwm0.Start();

            var pwm1 = new PWM(Cpu.PWMChannel.PWM_1, 300, 0, false);
            pwm1.Start();

            var pwm2 = new PWM(Cpu.PWMChannel.PWM_2, 300, 0, false);
            pwm2.Start();

            const int minBright = 0;
            const int maxBright = 100;
            int bright = minBright;
            int step = 1;

            while (true)
            {
                pwm0.DutyCycle = ToDutyCycle(bright);
                pwm1.DutyCycle = ToDutyCycleExp(bright);
                pwm2.DutyCycle = ToDutyCycle10(bright);

                bright += step;
                if (bright > maxBright || bright < minBright)
                {
                    bright = bright > maxBright ? maxBright : minBright;
                    step = -step;

                    Thread.Sleep(1000);
                }

                Thread.Sleep(40);
            }
        }
Пример #7
0
        public static void Main()
        {
            var led = new OutputPort(Pins.ONBOARD_LED, false);
            while(true)
            {
                led.Write(false);
                var requestUri = "http://dev3.aquepreview.com/helicoptersurface";
                Debug.Print("Setup");

                using (var request = (HttpWebRequest)WebRequest.Create(requestUri))
                {
                    request.Method = "GET";
                    Debug.Print("Requesting");

                    // send request and receive response
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        HttpStatusCode status = response.StatusCode;
                        if (status == HttpStatusCode.OK)
                        {
                            var pwm = new PWM(Pins.GPIO_PIN_D5);
                            Debug.Print("200, all ok");
                            pwm.SetDutyCycle(1000);
                            led.Write(true);
                        }
                    }
                }

                Thread.Sleep(2000);
            }
        }
Пример #8
0
 public PanTilter(Cpu.Pin panPin, int panMin, int panMax, Cpu.Pin tiltPin, int tiltMin, int tiltMax)
 {
     this.tilter = new PWM(tiltPin);
     this.tiltMin = tiltMin;
     this.tiltMax = tiltMax;
     this.tilter.SetDutyCycle(0);
 }
Пример #9
0
 /// <summary>
 /// Piezo speaker driver and notes and playback manager
 /// </summary>
 /// <param name="pin">From the SecretLabs.NETMF.Hardware.NetduinoPlus.PWMChannels namespace</param>
 /// <param name="name">Unique identifying name for command and control</param>
 public Piezo(Cpu.PWMChannel pin, string name)
     : base(name, "piezo")
 {
     //_piezo = new PWM(pin, 2048, 0, PWM.ScaleFactor.Milliseconds, false);
     _piezo = new PWM(pin, 2048, 0, false);
     _piezo.Start();
 }
Пример #10
0
 public PwmSpeaker(PWM pwm)
 {
     _pwm = pwm;
     _pwm.Frequency = 50;
     _pwm.DutyCycle = 0;
     _pwm.Start();
 }
Пример #11
0
 /// <summary>
 /// Common RGB-led
 /// </summary>
 /// <param name="RedPin">The PWM-pin connected to Red</param>
 /// <param name="GreenPin">The PWM-pin connected to Green</param>
 /// <param name="BluePin">The PWM-pin connected to Blue</param>
 /// <param name="CommonAnode">Specifies if the led is common anode</param>
 public RGBLed(Cpu.Pin RedPin, Cpu.Pin GreenPin, Cpu.Pin BluePin, bool CommonAnode = true)
 {
     this._Red = new PWM(RedPin);
     this._Green = new PWM(GreenPin);
     this._Blue = new PWM(BluePin);
     this._CommonAnode = CommonAnode;
 }
Пример #12
0
 public Motor(PWM.Pin pPin,Cpu.Pin ePin, int freq)
 {
     pwmPin = new PWM(pPin);
     frequency = freq;
     enablePin = new OutputPort(ePin, true); // PArte con enable alto (quindi motore spento)
     Set(50);
 }
Пример #13
0
        static double fadeAmount = 0.01; // brightness fade rate

        #endregion Fields

        #region Methods

        public static void Main()
        {
            // create a new outpot port using Pulse Width Modulation (PWM) and the onboard LED
            // PWM is a digital method of delivering a varying amount of power...
            // can be used to control the brightness of an LED or speed of a DC motor...
            PWM led = new PWM(SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_ONBOARD_LED, 100, 1.0, false);

            led.Start(); // enable the PWM LED

            // create a loop for the program to run in...
            while (true)
            {
                // PWM duty cycle value is a percentage of ON
                // 0.0 = 0%, while 1.0 = 100%
                led.DutyCycle = brightness;

                // scroll through the brightness at the rate of fadeAmount
                brightness = brightness + fadeAmount;

                // if we reach our limits...
                if (brightness <= 0.0 || brightness >= 0.99)
                {
                    // invert the fade rate to go in reverse direction
                    fadeAmount = -fadeAmount;
                }

                // sleep for 30ms, long enough to see the transistions
                Thread.Sleep(30);
            }
        }
Пример #14
0
        public RGBLed(Cpu.Pin red, Cpu.Pin green, Cpu.Pin blue, bool commonAnode = true) {
            _red = new PWM(red);
            _green = new PWM(green);
            _blue = new PWM(blue);

            CommonAnode = commonAnode;
        }
Пример #15
0
        /// <summary>
        /// During development, Main() acts as the ConsoleBootLoader, making it easy to debug the game.
        /// When game development is complete, comment out the content Main() to remove the overhead
        /// </summary>
        public static void Main() {
#if dev
            var joystickLeft = new AnalogJoystick(xAxisPin: Pins.GPIO_PIN_A0, yAxisPin: Pins.GPIO_PIN_A1);
            var joystickRight = new AnalogJoystick(xAxisPin: Pins.GPIO_PIN_A2, yAxisPin: Pins.GPIO_PIN_A3);
            var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);
            var speaker = new PWM(Pins.GPIO_PIN_D5);
            var resourceLoader = new SDResourceLoader();
            var buttonLeft = new PushButton(Pins.GPIO_PIN_D0, Port.InterruptMode.InterruptEdgeLevelLow, null, Port.ResistorMode.PullUp);
            var buttonRight = new PushButton(Pins.GPIO_PIN_D1, Port.InterruptMode.InterruptEdgeLevelLow, null, Port.ResistorMode.PullUp);
            var args = new object[(int)CartridgeVersionInfo.LoaderArgumentsVersion100.Size];

            var index = 0;
            args[index++] = CartridgeVersionInfo.CurrentVersion;
            args[index++] = joystickLeft;
            args[index++] = joystickRight;
            args[index++] = matrix;
            args[index++] = speaker;
            args[index++] = resourceLoader;
            args[index++] = buttonLeft;
            args[index] = buttonRight;

            matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation);
            matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode);
            matrix.SetDigitScanLimit(7);
            matrix.SetIntensity(8);

            Run(args);
#endif
        }
Пример #16
0
 /// <summary>
 /// LEDRGB Constructor.
 /// </summary>
 /// <param name="r">Red LED PWM channel</param>
 /// <param name="g">Green LED PWM channel</param>
 /// <param name="b">Blkue LED PWM channel</param>
 public LEDRGB(Cpu.PWMChannel r, Cpu.PWMChannel g, Cpu.PWMChannel b)
 {
     red = new PWM(r, 255, 0, PWM.ScaleFactor.Microseconds, false);
     green = new PWM(g, 255, 0, PWM.ScaleFactor.Microseconds, false);
     blue = new PWM(b, 255, 0, PWM.ScaleFactor.Microseconds, false);
     color = new RGBColor(0, 0, 0);
 }
Пример #17
0
        public static void Main()
        {
            count = 0;
            d     = DateTime.Now;
            c     = DateTime.Now;

            InputPort  digitalIn   = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.Disabled);
            OutputPort powerUpPort = new OutputPort(Pins.GPIO_PIN_D0, false);
            OutputPort healthOut0  = new OutputPort(Pins.GPIO_PIN_D1, false);
            OutputPort healthOut1  = new OutputPort(Pins.GPIO_PIN_D2, false);
            OutputPort healthOut2  = new OutputPort(Pins.GPIO_PIN_D4, false);
            OutputPort healthOut3  = new OutputPort(Pins.GPIO_PIN_D5, false);
            OutputPort healthOut4  = new OutputPort(Pins.GPIO_PIN_D7, false);
            OutputPort healthOut5  = new OutputPort(Pins.GPIO_PIN_D8, false);
            OutputPort healthOut6  = new OutputPort(Pins.GPIO_PIN_D9, false);

            OutputPort sanityPort = new OutputPort(Pins.GPIO_PIN_D13, true);

            infraredOut = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D6, 38000, .5, true);
            InterruptPort sender = new InterruptPort(Pins.GPIO_PIN_D10, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            sender.OnInterrupt += sender_OnInterrupt;
            state = TokenState.LISTEN;
            string message = "";


            while (true)
            {
                sanityPort.Write(true);
                GetPowerUp();
                DisplayHeath(healthOut0, healthOut1, healthOut2, healthOut3, healthOut4, healthOut5, healthOut6);
                powerUpPort.Write(powerUp);
                switch (state)
                {
                case TokenState.LISTEN:
                    GetListenByte(digitalIn);
                    break;

                case TokenState.STARTBYTE:
                    GetStartByte(digitalIn);
                    break;

                case TokenState.MESSAGE:
                    message = GetMessage(digitalIn);
                    break;

                case TokenState.ENDBYTE:
                    GetEndByte(digitalIn);
                    break;

                case TokenState.READ:
                    Debug.Print(String.Concat(message + " " + "PlayerHealth" + ": " + playerHeath, "\n"));
                    UpdatePlayer(message);
                    state   = TokenState.LISTEN;
                    message = "";
                    break;
                }
            }
        }
Пример #18
0
        public static void SendMessage(PWM infraredOut, OutputPort led, string message)
        {
            foreach (char c in message)
            {
                SendBit(infraredOut, led, c);

            }
        }
Пример #19
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();
        }
Пример #20
0
            static public void Initialize()
            {
                _pwm1 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
                _dir1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false);

                _pwm2 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di6);
                _dir2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, false);
            }
Пример #21
0
 public HS6635HBServo(Cpu.Pin pwmPin, uint minPulse = 900, uint centerPulse = 1500, uint maxPulse = 2100) {
     _servo = new PWM((Cpu.Pin)pwmPin);
     _servo.SetDutyCycle(0);
     MinRangePulse = minPulse;
     CenterRangePulse = centerPulse;
     MaxRangePulse = maxPulse;
     PulseRefreshRateMs = 20;
 }
Пример #22
0
 internal static void SetUpServo()
 {
     uint period = 20000;
     uint duration = SERVO_NEUTRAL;
     _servo = new PWM(PWMChannels.PWM_PIN_D5, period, duration, PWM.ScaleFactor.Microseconds, false);
     _servo.Start();
     _servoReady = true;
 }
Пример #23
0
        protected H.OutputPort _enablePort = null; // if enabled, then IsNeutral = false


        public HBridgeMotor(H.Cpu.PWMChannel a1Pin, H.Cpu.PWMChannel a2Pin, H.Cpu.Pin enablePin, float pwmFrequency = 1600)
        {
            this._pwmFrequency = pwmFrequency;
            // create our PWM outputs
            this._motorLeftPwm = new H.PWM(a1Pin, _pwmFrequency, 0, false);
            this._motorRighPwm = new H.PWM(a2Pin, _pwmFrequency, 0, false);
            this._enablePort   = new H.OutputPort(enablePin, false);
        }
        public static void Start()
        {
            _port = new PWM(PWMChannels.PWM_PIN_D9, 100, 0.5, false);
            _port.Frequency = 100;
            _port.DutyCycle = 0.5;

            _worker.Start();
            _port.Start();
        }
Пример #25
0
    public PiezoSpeaker(Cpu.Pin pin)
    {
        _pin = new PWM(pin);

        // take the pin low, so the speaker
        // doesn't make any noise until we
        // ask it to
        _pin.SetDutyCycle(0);
    }
Пример #26
0
        public Wheels(Cpu.Pin motorOneDirectionPin, Cpu.Pin motorOneSpeedPin,
                      Cpu.Pin motorTwoDirectionPin, Cpu.Pin motorTwoSpeedPin)
        {
            this.motorOneDirection = new OutputPort(motorOneDirectionPin, false);
            this.motorTwoDirection = new OutputPort(motorTwoDirectionPin, false);

            this.motorOneSpeed = new PWM(motorOneSpeedPin);
            this.motorTwoSpeed = new PWM(motorTwoSpeedPin);
        }
 public Zvucnik(Cpu.PWMChannel kojPin,KadePostaven kadeE)
 {
     _zvucnik = new PWM(kojPin, 100, 5, false);
     _zvucnik.DutyCycle = 50;
     _zvucnik.Frequency = 50;
     _zvucnik.Period = 1000;
     _kakovSum = TipSenzor.ZVUCNIK;
     this.KadeSum = kadeE;
 }
Пример #28
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);
        }
Пример #29
0
        /// <summary>
        /// Create the PWM Channel, set it low and configure timings
        /// </summary>
        /// <param name="pin"></param>
        public void Connect(Cpu.PWMChannel channelPin)
        {
            // Init the PWM pin
            servo = new PWM((Cpu.PWMChannel)channelPin, 20000, 1500, PWM.ScaleFactor.Microseconds, false);

            servo.DutyCycle = 0;
            // Typical settings
            range[0] = 1000;
            range[1] = 2000;
        }
Пример #30
0
		/// <summary>
		/// Enables the sound functionality if it was disabled.
		/// </summary>
        public static void Enable()
        {
			if (Sound.IsEnabled)
				return;

			Sound.AudioPowerControl.Write(true);
			Sound.PWMOut = new PWM(Sound.PWM_CHANNEL, 261, 50, false);

			Sound.Enabled = true;
        }
Пример #31
0
 public Wheel(Cpu.Pin controlPortA, Cpu.Pin controlPortB, Cpu.Pin powerPort)
 {
     MinPower = 45;
     MaxPower = 100;
     ControlPortA = new OutputPort(controlPortA, false);
     ControlPortB = new OutputPort(controlPortB, false);
     ControlPortP = new PWM(powerPort);
     SetSpeed(0, 0);
     Update();
 }
Пример #32
0
        public DCMotorDriver()
        {
            _pwm1 = new PWM((PWM.Pin)PortMap.motor1_PWM);
            _dir1a = new OutputPort((Cpu.Pin)PortMap.motor1_DirA, false);
            _dir1b = new OutputPort((Cpu.Pin)PortMap.motor1_DirB, false);

            _pwm2 = new PWM((PWM.Pin)PortMap.motor2_PWM);
            _dir2a = new OutputPort((Cpu.Pin)PortMap.motor2_DirA, false);
            _dir2b = new OutputPort((Cpu.Pin)PortMap.motor2_DirB, false);
        }
Пример #33
0
 /// <summary>
 /// Creates an instance of the motor driver.
 /// </summary>
 /// <param name="leftPwm">The pin connected to the left motor channel's PWM pin on the driver (PWMA)</param>
 /// <param name="leftForwardPin">The pin connected to the left motor channel's forward direction pin on the driver (AIN0)</param>
 /// <param name="leftReversePin">The pin connected to the left motor channel's reverse direction pin on the driver (AIN1)</param>
 /// <param name="rightPwm">The pin connected to the righ motor channel's PWM pin on the driver (PWMB)</param>
 /// <param name="rightForwardPin">The pin connected to the righ motor channel's forward direction pin on the driver (BIN0)</param>
 /// <param name="rightReversePin">The pin connected to the righ motor channel's reverse direction pin on the driver (BIN1)</param>
 /// <param name="standbyPin">The pin connected to the motor driver's standby pin (STBY) </param>
 public MotorDriver(
     PWM.Pin leftPwm, Cpu.Pin leftForwardPin, Cpu.Pin leftReversePin,
     PWM.Pin rightPwm, Cpu.Pin rightForwardPin, Cpu.Pin rightReversePin,
     Cpu.Pin standbyPin
     )
 {
     leftMotor = new Motor(leftPwm, leftForwardPin, leftReversePin);
     rightMotor = new Motor(rightPwm, rightForwardPin, rightReversePin);
     standbyPort = new OutputPort(standbyPin, false);
 }
Пример #34
0
        /// <summary>
        /// Create the PWM Channel, set it low and configure timings
        /// </summary>
        /// <param name="pin"></param>
        public Servo(Cpu.PWMChannel channelPin)
        {
            // Init the PWM pin
            // servo = new PWM((Cpu.PWMChannel)channelPin, 20000, 1500, PWM.ScaleFactor.Microseconds, false);
            servo        = new Microsoft.SPOT.Hardware.PWM((Cpu.PWMChannel)channelPin, 50000, 1500, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false);
            servo.Period = 50000;

            // Typical settings
            range[0] = 600;
            range[1] = 2100;
        }
Пример #35
0
        public static void Main()
        {
            count = 0;
            d     = DateTime.Now;
            InputPort  digitalIn  = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.Disabled);
            OutputPort ShieldPort = new OutputPort(Pins.GPIO_PIN_D0, false);
            OutputPort ManGunPort = new OutputPort(Pins.GPIO_PIN_D1, false);

            infraredOut = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D6, 38000, .5, true);

            InterruptPort sender = new InterruptPort(Pins.GPIO_PIN_D10, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            sender.OnInterrupt += sender_OnInterrupt;
            state = TokenState.LISTEN;
            string message = "";

            while (true)
            {
                switch (state)
                {
                case TokenState.LISTEN:
                    GetListenByte(digitalIn);
                    break;

                case TokenState.STARTBYTE:
                    GetStartByte(digitalIn);
                    break;

                case TokenState.MESSAGE:
                    message = GetMessage(digitalIn);
                    break;

                case TokenState.ENDBYTE:
                    GetEndByte(digitalIn);
                    break;

                case TokenState.READ:
                    if (message == "01")
                    {
                        ShieldPort.Write(true);
                        ManGunPort.Write(false);
                    }
                    else if (message == "10")
                    {
                        ShieldPort.Write(false);
                        ManGunPort.Write(true);
                    }
                    Debug.Print(String.Concat(message, "\n"));
                    state   = TokenState.LISTEN;
                    message = "";
                    break;
                }
            }
        }
Пример #36
0
        public TachometerApp()
        {
            Debug.Print("Here2");
            this._motor = new H.PWM(N.PWMChannels.PWM_PIN_D3, 100, 0, false);
            this._tach  = new LinearHallEffectTachometer(N.Pins.GPIO_PIN_D2);
            this._lcd   = new SerialLCD(new TextDisplayConfig()
            {
                Width = 16, Height = 2
            });

            this._tach.RPMsChanged += RPMsChanged;
        }
Пример #37
0
        /// <summary>
        /// Creates a new PwmLed on the specified PWM pin and limited to the appropriate
        /// voltage based on the passed `forwardVoltage`. Typical LED forward voltages
        /// can be found in the `TypicalForwardVoltage` class.
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="forwardVoltage"></param>
        public PwmLed(H.Cpu.PWMChannel pin, float forwardVoltage)
        {
            // validate and persist forward voltage
            if (forwardVoltage < 0 || forwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("forwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            this.ForwardVoltage = forwardVoltage;

            this._maximumPwmDuty = Helpers.CalculateMaximumDutyCycle(forwardVoltage);

            this._pwm = new H.PWM(pin, 100, this._maximumPwmDuty, false);
        }
Пример #38
0
        public StepperMotorController(CTRE.Phoenix.CANifier CANifier, CTRE.Phoenix.CANifier.GeneralPin directionPin, Microsoft.SPOT.Hardware.Cpu.PWMChannel movePin, uint maxSpeed,
                                      CTRE.Phoenix.CANifier.GeneralPin forwardLimitSwitchPin, CTRE.Phoenix.CANifier.GeneralPin reverseLimitSwitchPin)
        {
            lastDirection = Direction.STOPPED;

            this.maxSpeed = maxSpeed;

            this.directionPort      = directionPin;
            this.forwardLimitSwitch = forwardLimitSwitchPin;
            this.reverseLimitSwitch = reverseLimitSwitchPin;
            this.CANifier           = CANifier;

            movePort = new PWM(movePin, maxSpeed, maxSpeed / 2, PWM.ScaleFactor.Microseconds, false);
        }
Пример #39
0
        public static void Main()
        {
            var infraredOut = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D6, 38000, .5, true); //50% brightness
            var led         = new OutputPort(Pins.ONBOARD_LED, false);

            string message  = "10110100";
            string message2 = "10111000";

            while (true)
            {
                SendMessage(infraredOut, led, message);
                var temp = message;
                message  = message2;
                message2 = temp;
            }
        }
Пример #40
0
        public static void Main()
        {
            infraredOut = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D6, 38000, .5, true);
            InterruptPort sender = new InterruptPort(Pins.GPIO_PIN_D10, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            OutputPort ammoOut0 = new OutputPort(Pins.GPIO_PIN_D0, false);
            OutputPort ammoOut1 = new OutputPort(Pins.GPIO_PIN_D1, false);
            OutputPort ammoOut2 = new OutputPort(Pins.GPIO_PIN_D2, false);
            OutputPort ammoOut3 = new OutputPort(Pins.GPIO_PIN_D3, false);

            sender.OnInterrupt += sender_OnInterrupt;

            while (true)
            {
                GetPowerUp();
                DisplayAmmo(ammoOut0, ammoOut1, ammoOut2, ammoOut3);
            }
        }
Пример #41
0
        protected void InitializePeripherals()
        {
            _rtc = new DS3231(0x68, 100);
            // Run once to adjust the time on the RTC
            // _rtc.CurrentDateTime = new DateTime(2018, 12, 17, 22, 41, 0);

            _lcd = new Lcd2004
                   (
                RS: N.Pins.GPIO_PIN_D8,
                E: N.Pins.GPIO_PIN_D9,
                D4: N.Pins.GPIO_PIN_D10,
                D5: N.Pins.GPIO_PIN_D11,
                D6: N.Pins.GPIO_PIN_D12,
                D7: N.Pins.GPIO_PIN_D13
                   );

            H.PWM _contrast = new H.PWM(H.Cpu.PWMChannel.PWM_0, 1000, 0.6, false);
            _contrast.Start();
        }
Пример #42
0
        public static void Main()
        {
            var infraredOut = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D6, 38000, .5, true); //50% brightness
            var led         = new OutputPort(Pins.ONBOARD_LED, false);

            string message  = "10110100";
            string message2 = "10111000";

            while (true)
            {
                count++;
                SendMessage(infraredOut, led, message);
                Debug.Print(count + ": " + message);

                count++;
                SendMessage(infraredOut, led, message2);
                Debug.Print(count + ": " + message2);
            }
        }
Пример #43
0
        /// <summary>
        ///
        /// Implementation notes: Architecturally, it would be much cleaner to construct this class
        /// as three PwmLeds. Then each one's implementation would be self-contained. However, that
        /// would require three additional threads during ON; one contained by each PwmLed. For this
        /// reason, I'm basically duplicating the functionality for all three in here.
        /// </summary>
        /// <param name="redPin"></param>
        /// <param name="greenPin"></param>
        /// <param name="bluePin"></param>
        /// <param name="isCommonCathode"></param>
        public RgbPwmLed(
            H.Cpu.PWMChannel redPin, H.Cpu.PWMChannel greenPin, H.Cpu.PWMChannel bluePin,
            float redLedForwardVoltage   = TypicalForwardVoltage.ResistorLimited,
            float greenLedForwardVoltage = TypicalForwardVoltage.ResistorLimited,
            float blueLedForwardVoltage  = TypicalForwardVoltage.ResistorLimited,
            bool isCommonCathode         = true)
        {
            // validate and persist forward voltages
            if (redLedForwardVoltage < 0 || redLedForwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("redLedForwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            RedForwardVoltage = redLedForwardVoltage;
            if (greenLedForwardVoltage < 0 || greenLedForwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("greenLedForwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            GreenForwardVoltage = greenLedForwardVoltage;
            if (blueLedForwardVoltage < 0 || blueLedForwardVoltage > 3.3F)
            {
                throw new ArgumentOutOfRangeException("blueLedForwardVoltage", "error, forward voltage must be between 0, and 3.3");
            }
            BlueForwardVoltage = blueLedForwardVoltage;
            // calculate and set maximum PWM duty cycles
            _maximumRedPwmDuty   = Helpers.CalculateMaximumDutyCycle(RedForwardVoltage);
            _maximumGreenPwmDuty = Helpers.CalculateMaximumDutyCycle(GreenForwardVoltage);
            _maximumBluePwmDuty  = Helpers.CalculateMaximumDutyCycle(BlueForwardVoltage);

            IsCommonCathode = isCommonCathode;
            RedPin          = redPin;
            GreenPin        = greenPin;
            BluePin         = bluePin;

            RedPwm   = new H.PWM(RedPin, 100, 0, false);
            GreenPwm = new H.PWM(GreenPin, 100, 0, false);
            BluePwm  = new H.PWM(BluePin, 100, 0, false);
        }
        public override void Set(uint period, uint highTime, SocketInterfaces.PwmScaleFactor factor)
        {
            if (_port == null)
            {
                _port = new Hardware.PWM(_channel, period, highTime, (Hardware.PWM.ScaleFactor)factor, _invert);

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

                _port.Scale    = (Hardware.PWM.ScaleFactor)factor;
                _port.Period   = period;
                _port.Duration = highTime;

                _port.Start();
                _started = true;
            }
        }
Пример #45
0
 public PWMStruct(Microsoft.SPOT.Hardware.PWM pwm, int position)
 {
     Pwm        = pwm;
     Position   = position;
     LastOffset = 0;
 }
Пример #46
0
        public static void Main()
        {
            _lcdShield = new DfRobotLcdShield(20, 4);

            // Create a custom degrees symbol (°), store it on the LCD for later use with the lat/long display
            _lcdShield.CreateChar(0, new byte[] { 0x0, 0x4, 0xa, 0x4, 0x0, 0x0, 0x0, 0x0 });

            // 0 bars are not required as that would just require sending " "
            _lcdShield.CreateChar(1, new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1F });
            _lcdShield.CreateChar(2, new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1F, 0x1F });
            _lcdShield.CreateChar(3, new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x1F, 0x1F, 0x1F });
            _lcdShield.CreateChar(4, new byte[] { 0x0, 0x0, 0x0, 0x0, 0x1F, 0x1F, 0x1F, 0x1F });
            _lcdShield.CreateChar(5, new byte[] { 0x0, 0x0, 0x0, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F });
            _lcdShield.CreateChar(6, new byte[] { 0x0, 0x0, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F });
            _lcdShield.CreateChar(7, new byte[] { 0x0, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F });
            // 8 bars are not required as that would just require sending byte 255.

#if (NETDUINO)
            _thunderbolt = new ThunderBolt("COM1", AngleUnits.Degrees, AltitudeUnits.Meters, new OutputPort(Pins.GPIO_PIN_D13, false));
#endif
#if (FEZLEMUR)
            _thunderbolt = new ThunderBolt("COM1", AngleUnits.Degrees, AltitudeUnits.Meters, new OutputPort(GHI.Pins.FEZLemur.Gpio.D13, false));
#endif

#if (NTP)
            _ntpServer = new NtpServer();
#endif

            _lcdShield.OnButtonPressed += LcdshieldOnOnButtonPressed;

            DisplaySplash();

#if (NETDUINO)
            var backlight = new Microsoft.SPOT.Hardware.PWM(PWMChannels.PWM_PIN_D10, 10000, LcdBrightness / 100d, false);
            backlight.Start();
#endif

            TestLeds();

            _thunderbolt.Open();
            _thunderbolt.TimingMode = TimingModes.UTC;
            _thunderbolt.RequestManufacturingParameters();
            _thunderbolt.RequestFirmwareVersion();
            _thunderbolt.SetupUnitForDisciplining();
            _thunderbolt.RequestTrackedSatelliteStatus();

            _thunderbolt.TimeChanged += ThunderboltOnTimeChanged;

            Thread.Sleep(3000);

            DisplayVersion();

#if (NTP)
            _ntpServer.Start();
#endif

            while (true)
            {
                if (_thunderbolt.IsSerialDataBeingReceived)
                {
                    if (!_isSurveyInProgress && _thunderbolt.IsSurveyInProgress())
                    {
                        // Survey has just started.  Jump to the page displaying survey progress.
                        _previousPageNumber = _pageNumber; // Take note of the page we were on so we can switch back later.
                        _isSurveyInProgress = true;
                        _pageNumber         = 2;           // Set the new page to jump to.
                    }
                    else if (_isSurveyInProgress && !_thunderbolt.IsSurveyInProgress())
                    {
                        // Survey has just finished.  Jump to the previous page we were displaying.
                        _pageNumber         = _previousPageNumber;
                        _isSurveyInProgress = false;
                    }

                    switch (_pageNumber)
                    {
                    case 1:
                        DisplayScreenOne();
                        break;

                    case 2:
                        DisplayScreenTwo();
                        break;

                    case 3:
                        DisplayScreenThree();
                        break;

                    case 4:
                        DisplayScreenFour();
                        break;

                    case 5:
                        DisplaySatelliteSignalScreen();
                        break;

                    case 6:
                        DisplayPRNScreen();
                        break;

                    case 7:
                        DisplayDOPScreen();
                        break;

#if (NTP)
                    case 8:
                        DisplayScreenNTP();
                        break;
#endif
                    default:
                        DisplayScreenOne();
                        break;
                    }

                    UpdateAlarmIndicators();
                }
                else
                {
                    DisplayNoSerialDataScreen();
                }
            }
        }
Пример #47
0
        public PWM(Cpu.Pin pin)
        {
            var channel = GetChannelFromPin(pin);

            _pwm = new Microsoft.SPOT.Hardware.PWM(channel, 100, 0, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false);
        }
Пример #48
0
 /// <summary>
 /// Instantiates a new Servo on the specified PWM Pin with the specified config.
 /// </summary>
 /// <param name="pin"></param>
 /// <param name="config"></param>
 public ServoBase(H.Cpu.PWMChannel pin, ServoConfig config)
 {
     _config = config;
     _pwm    = new H.PWM(pin, config.Frequency, 0, false);
 }