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);
            }
        }
Esempio n. 2
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;
 }
Esempio n. 3
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);
    }
Esempio n. 4
0
        /// <summary>
        /// Create the PWM pin, set it low and configure timings
        /// </summary>
        /// <param name="pin"></param>
        public Servo(Cpu.Pin pin)
        {
            // Init the PWM pin
            servo = new PWM((Cpu.Pin)pin);

            servo.SetDutyCycle(0);

            // Typical settings
            range[0] = 1000;
            range[1] = 2000;
        }
Esempio n. 5
0
        public ServoController(Cpu.Pin pin, int minDuration, int maxDuration, uint period = 20000, int startDegree = 0)
        {
            _minDuration = minDuration;
            _maxDuration = maxDuration;
            _range = maxDuration - minDuration;
            _period = period;
            _servo = new PWM(pin);
            _servo.SetDutyCycle(0);

            if (startDegree > 0)
                Rotate(startDegree);
        }
Esempio n. 6
0
        public static void Main()
        {
            // write your code here
            PWM led = new PWM(Pins.GPIO_PIN_D5);
            AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);
            pot.SetRange(0, 100);
            int potValue = 0;

            while (true)
            {
                potValue = pot.Read();
                led.SetDutyCycle((unit)potValue);
            }
        }
        public static void Main()
        {
            uint watchdogTimer = 1000;

            PWM umbrella = new PWM(Pins.GPIO_PIN_D10); //Right controller

            Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            receiveSocket.Bind(new IPEndPoint(IPAddress.Any, 4444));
            byte[] rxData = new byte[10]; // Incoming data buffer
            double raw_speed = 0;

            while (true) /* Main program loop */
            {
                /* Try to receive new data - spend 100uS waiting */
                if (receiveSocket.Poll(100, SelectMode.SelectRead))
                {
                    int rxCount = receiveSocket.Receive(rxData);
                    watchdogTimer = 0;
                }

                if (watchdogTimer < 200)   // Only enable the robot if data was received recently
                {
                    // 900 (full rev) to 2100 (full fwd), 1500 is neutral

                    raw_speed += (rxData[0] - 127.5) * .001; // Add the value of the stick to the current speed
                    // Mediate added speed to negative if it's below center line(on ipgamepad). Make the added speed very little because the mount of UDP packets is large.
                    // map function only accept input between 0-255
                    if (raw_speed < 0)
                    {
                        raw_speed = 0;
                    }
                    else if (raw_speed > 255)
                    {
                        raw_speed = 255;
                    }
                    // Stick maintains speed unless calibrate changes.
                    umbrella.SetPulse(20000, map((uint)raw_speed, 0, 255, 1500, 2100)); // Right controller 1500-2100 -- only positive

                    watchdogTimer++;
                }
                else
                {
                    // Disable the robot
                    umbrella.SetDutyCycle(0);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Create the PWM pin, set it low and configure timings
        /// </summary>
        /// <param name="pin"></param>
        public Servo(Cpu.Pin pin)
        {
            // Init the PWM pin
            // servo = new PWM((Cpu.Pin)pin);
            
            servo = new PWM((Cpu.PWMChannel)pin, 10000, 0.1, false);
            servo.Period((uint)0); 
            servo.SetDutyCycle(0);

            // Typical settings
            range[0] = 1000;
            range[1] = 2000;

            // jha v1.2
            forwardRange = 100;
            reverseRange = -100;
        }
Esempio n. 9
0
        /// <summary>
        /// Create the PWM pin, set it low and configure timings
        /// </summary>
        /// <param name="pin"></param>
        public ServoControl(Cpu.Pin pin)
        {
            try
            {
                // Init the PWM pin
                servo = new PWM(pin);

                servo.SetDutyCycle(0);

                // Typical settings
                range[0] = 1000;
                range[1] = 2000;
            }
            catch(Exception ex)
            {

            }
        }
Esempio n. 10
0
        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 = "C1C1C1g1a1a1g2E1E1D1D1C2u";

            PWM speaker = new PWM(Pins.GPIO_PIN_D5);

            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.SetPulse(noteDuration * 2, noteDuration);
                Thread.Sleep(beatTimeInMilliseconds * beatCount - pauseTimeInMillisenconds);

                speaker.SetDutyCycle(0);
                Thread.Sleep(pauseTimeInMillisenconds);
            }

            Thread.Sleep(Timeout.Infinite);
        }
Esempio n. 11
0
        private OutputPort MotorLatch, MotorEnable, MotorClk, MotorData; // 74HCT595 commands

        #endregion Fields

        #region Constructors

        // Steper sequences for each stepper. Have a look here : http://www.stepperworld.com/Tutorials/pgBipolarTutorial.htm
        //private byte[][] BipolarSteppingWaveDrive = new byte[][] {  new byte [] {4,2,8,16},
        //                                                            new byte [] {1,128,64,32}};
        //private byte[][] BipolarSteppingHiTorque = new byte[][] {   new byte [] {20,24,10,6},
        //                                                            new byte [] {129,192,96,33}};
        //private byte[][] BipolarSteppingHalfStep = new byte[][] {   new byte [] {4,20,16,24,8,10,2,6},
        //                                                            new byte [] {1,129,128,192,64,96,32,33}};
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="driver"> Which driver to initialize : 1=driver 1, 2=driver 2, 3=both</param>
        public Mshield()
        {
            //UsedDriver = driver;
            //if (driver == Drivers.Driver1 || driver == Drivers.Both)
            //{
            //    Motor1A = new OutputPort(Pins.GPIO_PIN_D11, false);
            //    Motor1B = new OutputPort(Pins.GPIO_PIN_D3, false);
            //}
            //if (driver == Drivers.Driver2 || driver == Drivers.Both)
            //{
                Motor2A = new PWM(Pins.GPIO_PIN_D5);
                Motor2A.SetDutyCycle(0);
                Motor2B = new PWM(Pins.GPIO_PIN_D6);
                Motor2B.SetDutyCycle(0);
            //}
            MotorLatch = new OutputPort(Pins.GPIO_PIN_D12, true);
            MotorEnable = new OutputPort(Pins.GPIO_PIN_D7, false);
            MotorClk = new OutputPort(Pins.GPIO_PIN_D4, true);
            MotorData = new OutputPort(Pins.GPIO_PIN_D8, true);

            latch_state = 0;
            latch_tx();
        }
Esempio n. 12
0
        /// <summary>
        /// Create a tlc device, and configure it to communicate on the SPI interface. Set the SPI settings to neutral:
        /// new SPI.Configuration(Pins.GPIO_PIN_D8, false, 0, 0, ...  , where the pin number can be the latch pin 
        /// 
        /// </summary>
        /// <param name="config">The SPI configuration. </param>
        /// <param name="PWMchannel1">Channel for the GSCLK pin</param>
        /// <param name="PWMChannel2">Channel for the BLANK pin</param>
        /// <param name="LATCHpin">Required output channel</param>
        /// <param name="channelCount">Must be max Channelcount provided by the Tlc5940</param>
        public Tlc5940(SPI.Configuration config, PWM gsclk, PWM blank, OutputPort LATCHport, uint channelCount)
        {
            useSPIInterface = true;

            SPIDevice = config;
            SPIBus = new SPI(SPIDevice);

            GSCLKPin = gsclk;
            BLANKPin = blank;
            XLATpin = LATCHport;
            ValidateChannelCount(channelCount);
            writeBuffer = CreateBuffer(channelCount);
            // Clear the channels, and disable the output
            GSCLKPin.SetDutyCycle(0);
            BLANKPin.SetDutyCycle(0);
            XLATpin.Write(false);
            GSCLKPin.SetPulse(gsclk_period, 1);
            //BLANKPin.SetPulse((gsclk_period * 4096), 1);
            BLANKPin.SetPulse((gsclk_period)*(4096/2), 1);
            //BLANKPin.SetPulse((gsclk_period + 1)*(4096/2), 1);

            // THis is the arduino formula:
        }
Esempio n. 13
0
        public static void Main()
        {
            var dummyTest = true;
            //Connect real Input Ports to ground !

            //3 Examples:
            //    1. "normal"
            //    2. interrupt driven
            //    3. PWM driven on port D5 !!

            var runSample = 1;
            switch (runSample)
            {   // "normal"
                case 1:
                    switchPort = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
                    while (dummyTest)
                    {
                        if (!switchPort.Read() || !realSwitchPort.Read() || !realSwitchPort1.Read() || !realSwitchPort2.Read())
                        {
                            ledPort.Write(true);
                            realLedPort.Write(true);
                            sleepTime = 500;
                            if (!realSwitchPort1.Read()) sleepTime = 300;
                            if (!realSwitchPort2.Read()) sleepTime = 100;
                        }
                        Thread.Sleep(sleepTime);
                        ledPort.Write(false);
                        realLedPort.Write(false);
                        Thread.Sleep(sleepTime);
                    }
                    break;
                case 2:
                    // Interrupt Sample:
                    interruptPort = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
                    interruptPort.OnInterrupt += new NativeEventHandler(interruptPort_OnInterrupt);
                    while (dummyTest)
                    {
                    }
                    break;
                case 3:
                    // use PWM Port ..
                    var realLedPortPWM = new PWM(Pins.GPIO_PIN_D5);
                    uint outPWM = 0; bool up = true;
                    while (dummyTest)
                    {
                        if (up)
                        {
                            outPWM++;
                            if (outPWM >= 100)
                            {
                                up = false;
                            }
                        }
                        else
                        {
                            outPWM--;
                            if (outPWM <= 0)
                            {
                                up = true;
                            }
                        }
                        realLedPortPWM.SetDutyCycle(outPWM);
                        Thread.Sleep(8);
                    }
                    break;
                default:
                    Debug.Print("This is no choice -- you are doomed!");
                    break;
            }
        }
Esempio n. 14
0
 public Servo(Cpu.Pin pin)
 {
     servo = new PWM(pin);
     servo.SetDutyCycle(dutyCycle: 0);
 }