Joystick event not being fired

I have connected the Joystick to FEZ Spider and doing some basic writing on the Display but the events are not fired when i move the joystick, what could be the reason

  joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);
            display.SimpleGraphics.DisplayText("Starting", Resources.GetFont(Resources.FontResources.small), GT.Color.Red, 5, 5);

            joystick.JoystickReleased += new Joystick.JoystickEventHandler(joystick_JoystickReleased);

 void joystick_JoystickReleased(Joystick sender, Joystick.JoystickState state)
        {
            display.SimpleGraphics.DisplayText("joy stick moved", Resources.GetFont(Resources.FontResources.small), GT.Color.Red, 5, 5);
        }

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            display.SimpleGraphics.DisplayText("joy stick moved",Resources.GetFont(Resources.FontResources.small),GT.Color.Red,5,5);
   
            
        }

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)

Hi there and welcome to the community…
Please try using


Debug.Print("event received");


instead of :


             display.SimpleGraphics.DisplayText("joy stick moved", Resources.GetFont(Resources.FontResources.small), GT.Color.Red, 5, 5);

while debugging…

and if you want to test it outside iof VS2010…

try


Mainboard.SetDebugLED(true); // this will turn on the LED on your mainboard.

@ irizvi - The JoystickPressed and JoystickReleased events are specific to the joystick’s built-in button (that is, if you press downward on the joystick, as opposed to deflecting it to the side, it will “click” and the JoystickPressed event will be raised. When you release it, the JoystickReleased event will be raised).

If you want to get the value from the joystick, you need to use the following code, usually within a timer:

void timer_Tick(GT.Timer timer)
{
    Joystick.Position pos = joystick.GetJoystickPosition();

    paramX = pos.X;
    paramY = pos.Y;
}

PS - in future posts, please use the code button above (looks like a series of 1s and 0s) to wrap your code, which makes it much more readable.

1 Like

@ irizvi -

Does it make a big difference to use a thread vs. a timer to poll the Joystick position? I’ve not tried it using a thread, just using a timer, which has generally been adequate for my needs.