Beispiel #1
0
        public static void Main()
        {
            // Declares the joystick
            ThumbJoystick Joystick = new ThumbJoystick(new Netduino.ADC(Pins.GPIO_PIN_A0), new Netduino.ADC(Pins.GPIO_PIN_A1), Pins.GPIO_PIN_D2);

            // Prints all values from the joystick every second
            while (true)
            {
                Debug.Print("Horz:" + Joystick.HorizontalValue.ToString() + " - Vert:" + Joystick.VerticalValue.ToString() + " - Sel:" + Joystick.PushValue.ToString());
                Thread.Sleep(1000);
            }

        }
Beispiel #2
0
        public static void Main()
        {
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // !  W A R N I N G   W A R N I N G   W A R N I N G    W A R N I N G   W A R N I N G   W A R N I N G  !
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // ! The Joystick Shield analog ports are connected to 5V since it's originally designed for Arduino. !
            // ! The Netduino analog inputs work on 3.3V. Herefor a modification to the shield is required.       !
            // ! See http://netmftoolbox.codeplex.com/wikipage?title=Joystick%20Shield  for more details.         !
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            // The thumb joystick is connected to analog pins 0 and 1, and digital pin 2
            // On the Joystick shield, the thumb stick is rotated by 90° so we need to invert the horizontal value
            ThumbJoystick Joystick = new ThumbJoystick(new Netduino.ADC(Pins.GPIO_PIN_A0), new Netduino.ADC(Pins.GPIO_PIN_A1), Pins.GPIO_PIN_D2, true);

            // The other buttons are connected to digital pins 3, 4, 5 and 6
            // The shield doesn't have pull-up resistors so we use the internal ones from the Netduino
            InputPort ButtonRight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp);
            InputPort ButtonUp = new InputPort(Pins.GPIO_PIN_D4, false, Port.ResistorMode.PullUp);
            InputPort ButtonDown = new InputPort(Pins.GPIO_PIN_D5, false, Port.ResistorMode.PullUp);
            InputPort ButtonLeft = new InputPort(Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);

            // Infinite loop; so far Analog ports can't handle interrupts, so the Joystick driver can't as well
            while (true)
            {
                // Lets start with an empty string
                string OutputText = "";
                // Add the values of the thumb stick
                OutputText = "Horizontal: " + Joystick.HorizontalValue.ToString();
                OutputText += " Vertical: " + Joystick.VerticalValue.ToString();
                if (Joystick.PushValue) OutputText += " Thumbstick pushed";

                // Add button states to the output text (inverted with the ! because of the pull-up resistor)
                if (!ButtonDown.Read()) OutputText += " Button Down";
                if (!ButtonUp.Read()) OutputText += " Button Up";
                if (!ButtonLeft.Read()) OutputText += " Button Left";
                if (!ButtonRight.Read()) OutputText += " Button Right";

                // Displays the output text to the debug window
                Debug.Print(OutputText);

                // Wait 100ms to read the pins again
                Thread.Sleep(100);
            }
        }