ButtonEventHandler fails to fire and broken web link

Hi, I am doing the Getting Started with FEZ Spider and my button event handler will not fire. I have been reading past forum threads on this subject and some point to http://tinyclr.com/forum/21/4373/ for the solution. Unfortunately this link is broken. Does anyone know where I can find it? Thanks.

Can you tell us what button module version you have? Do you have a joystick module as well, and if so can you try the same code with the joystick connected and push it in and see if that fires?

Hi Brett. The buttons are version 1.3. The joystick push event works. This is an early kit purchased in November 2011 and I have put firmware 4.1 on it.

My personal view is that you should use the latest 4.2 SDK and install the 4.2 firmware, even though you might have a bit more work to get “examples” working. The previous threads also seemed to mention drivers, so by moving to the later update you should have the latest driver too that might address the issue.

might also help to post your code. a common reason for a button not firing is not exiting the ProgramStarted() method.

Hi Brett and Mike. I have stepped through the code and it is exiting the ProgramStart() method. My code is below. I will takes Brett’s advise and upgrade to 4.2 SDK. Thanks.

=============== Program.generated.cs =======================

using Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerCamera
    public partial class Program : Gadgeteer.Program
        // GTM.Module defintions
		Gadgeteer.Modules.GHIElectronics.Button button;
		Gadgeteer.Modules.GHIElectronics.Button button1;
		Gadgeteer.Modules.GHIElectronics.MulticolorLed led;
		Gadgeteer.Modules.GHIElectronics.MulticolorLed led1;
		Gadgeteer.Modules.GHIElectronics.Joystick joystick;
		Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClient;

		public static void Main()
			//Important to initialize the Mainboard first
            Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();			

            Program program = new Program();
            program.Run(); // Starts Dispatcher

        private void InitializeModules()
			// Initialize GTM.Modules and event handlers here.		
			usbClient = new GTM.GHIElectronics.UsbClientDP(1);
			led1 = new GTM.GHIElectronics.MulticolorLed(4);
			button1 = new GTM.GHIElectronics.Button(6);
			led = new GTM.GHIElectronics.MulticolorLed(8);
			joystick = new GTM.GHIElectronics.Joystick(9);
			button = new GTM.GHIElectronics.Button(11);


================= Program.cs ===========================

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerCamera
    public partial class Program
        void ProgramStarted()
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            button1.ButtonPressed += new Button.ButtonEventHandler(button1_ButtonPressed);
            joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);
            //camera.PictureCaptured += new Camera.PictureCapturedEventHandler(camera_PictureCaptured);
            button.TurnLEDOn();                         //  <- works
            button1.TurnLEDOff();                       //  <- works
            led.BlinkRepeatedly(GT.Color.Orange);       //  <- works, albeit violet!
            led1.BlinkRepeatedly(GT.Color.Green);       //  <- works, albeit blue!
            Debug.Print("Program Started");
        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {   // this works!
        void button1_ButtonPressed(Button sender, Button.ButtonState state)
        {   // doesn't work
            // Debug.Print("button1_ButtonPressed");
        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {   // doesn't work
        //void camera_PictureCaptured(Camera sender, GT.Picture picture)
        //    // display removed for now until button event works.
        //    //display.SimpleGraphics.DisplayImage(picture, 5, 5);

let me also reiterate my “joystick” comment.

Don’t add new code, your app still needs to LOGICALLY (in Gadgeteer designer) have the BUTTON connected to a specific socket, but instead of PHYSICALLY connecting the button on that socket connect the joystick. It’s press is detected the same way, so will show you that the socket you’ve chosen is working and the code is correct, and that the debounce issue you pointed to is at fault.

Yahoo progress: if I plug a joystick into a port setup for one of the buttons the button event fires. So what does this mean? Two faulty button modules? That seems very unlikely.

If it fires, then it’s either a hardware issue or a driver/hardware interaction issue. I’d suggest going to the latest 4.2 SDK and creating the new Gadgeteer app and check again.

Gus/GHI, what was the final resolution of the debounce issue pointed out in http://www.ghielectronics.com/community/forum/topic?id=4276 ?

@ Brett - fixed long ago

Hi Brett. I have gone to 4.2 and the problem is fixed. Thank you all for helping.

@ SMiller - let’s keep things simple. Make a new project with one button handler please. Then try to plug in the joystick or the button in the same socket. Does one or both work?

What is your firmware version?

@ Gus, I really just meant what was the resolution, a hardware rev or a driver change? But since the issue is now resolved, I suspect it was the driver.

It was code