Esempio n. 1
0
        public DcMotor(MotorHeaders header)
        {
            switch (header)
            {
            case MotorHeaders.M3:
                _motorBitA = (int)MotorBits.Motor3A;
                _motorBitB = (int)MotorBits.Motor3B;
                _pwm       = new PWM(MotorShield.Pwm_0B);
                break;

            case MotorHeaders.M4:
                _motorBitA = (int)MotorBits.Motor4A;
                _motorBitB = (int)MotorBits.Motor4B;
                _pwm       = new PWM(MotorShield.Pwm_0A);
                break;

            default:
                throw new InvalidOperationException("Invalid motor header specified.");
            }

            MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitA) & ~(1 << _motorBitB));
            MotorShield.Instance.LatchTx();

            _pwm.SetPulse(100, 0);
        }
Esempio n. 2
0
        //UART
        static void receivedDataUsingCOMPort(object sender, SerialDataReceivedEventArgs e)
        {
            SecretLabs.NETMF.Hardware.PWM speaker = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5);
            try
            {
                if (spUART.BytesToRead > 0)
                {
                    byte[] buffer = new byte[spUART.BytesToRead];
                    spUART.Read(buffer, 0, buffer.Length);
                    char[] cReceived = System.Text.Encoding.UTF8.GetChars(buffer, 0, buffer.Length);

                    string strReceived = new string(cReceived);
                    Debug.Print("command string received " + strReceived);

                    if (cReceived[0] == 'N')
                    {
                        led.Write(true);
                    }
                    else if (cReceived[0] == 'F')
                    {
                        led.Write(false);
                    }
                    //MOTION SENSOR - PIEZO BUZZER TURN ON
                    else if (cReceived[0] == 'A')
                    {
                        Debug.Print("Alarm sounding");
                        for (int i = 0; i < 5; i++)
                        {
                            uint duration1 = 1000, duration2 = 1000;
                            speaker.SetPulse(duration1 * 2, duration1);
                            Thread.Sleep(100);
                            speaker.SetPulse(duration2 * 2, duration2);
                            Thread.Sleep(100);
                            speaker.SetPulse(duration1 * 2, duration1);
                            Thread.Sleep(100);
                            speaker.SetPulse(duration2 * 2, duration2);
                            Thread.Sleep(100);
                            speaker.SetDutyCycle(0);
                        }
                    }
                    //PIEZO BUZZER TURN OFF
                    //else if (cReceived[0] == 'B')
                    // {
                    //    Debug.Print("Turned off alarm");
                    //    speaker.SetDutyCycle(0);
                    // }
                }
            }

            catch (Exception ex)
            {
                Debug.Print("exception " + ex.Message.ToString());
            }
        }
Esempio n. 3
0
        public static void Main()
        {
            //
            SecretLabs.NETMF.Hardware.PWM led = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5);
            AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);

            pot.SetRange(0, 100);

            int potValue = 0;

            while (true)
            {
                //read potentiometer value
                potValue = pot.Read();

                //change LED intensity based on potentiometer value
                led.SetDutyCycle((uint)potValue);
            }
        }
Esempio n. 4
0
        public DcMotor(MotorHeaders header)
        {
            switch (header)
            {
                case MotorHeaders.M3:
                    _motorBitA = (int)MotorBits.Motor3A;
                    _motorBitB = (int)MotorBits.Motor3B;
                    _pwm = new PWM(MotorShield.Pwm_0B);
                    break;
                case MotorHeaders.M4:
                    _motorBitA = (int)MotorBits.Motor4A;
                    _motorBitB = (int)MotorBits.Motor4B;
                    _pwm = new PWM(MotorShield.Pwm_0A);
                    break;
                default:
                    throw new InvalidOperationException("Invalid motor header specified.");
            }

            MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitA) & ~(1 << _motorBitB));
            MotorShield.Instance.LatchTx();

            _pwm.SetPulse(100, 0);
        }
Esempio n. 5
0
 public void SetPins(Cpu.Pin _redpin, Cpu.Pin _greenpin, Cpu.Pin _bluepin)
 {
     if (RedPWM != null)
     {
         RedPWM.Dispose();
     }
     RedPWM = new PWM(_redpin);
     RedPWM.SetDutyCycle(0);
     if (GreenPWM != null)
     {
         GreenPWM.Dispose();
     }
     GreenPWM = new PWM(_greenpin);
     GreenPWM.SetDutyCycle(0);
     if (BluePWM != null)
     {
         BluePWM.Dispose();
     }
     BluePWM = new PWM(_bluepin);
     BluePWM.SetDutyCycle(0);
 }
Esempio n. 6
0
 /// <summary>Defines a Netduino PWM pin</summary>
 /// <param name="Pin">The Netduino pin</param>
 public PWM(Cpu.Pin Pin)
 {
     this._port = new SL.PWM(Pin);
 }
Esempio n. 7
0
 /// <summary>Defines a Netduino PWM pin</summary>
 /// <param name="Pin">The Netduino pin</param>
 public PWM(Cpu.Pin Pin)
 {
     this._port = new SL.PWM(Pin);
 }
Esempio n. 8
0
 public void Setup()
 {
     redLed = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D9);
     blueLed = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D10);
     greenLed = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D11);
 }
Esempio n. 9
0
 public void Attach(Cpu.Pin servoPin)
 {
     servoPort = new SecretLabs.NETMF.Hardware.PWM(servoPin);
 }
Esempio n. 10
0
 public void Setup()
 {
     redLed   = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D9);
     blueLed  = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D10);
     greenLed = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D11);
 }