Main Site Documentation

Button Click not firing


#1

Hello,

Purchased a FEZ Start kit, IR Receiver, Ethernet shield, and Servo controller. This is for a home automation hobby project.

So far I’ve gotten everything up and running, Tivo remote (thumbs up and thumds down) control a servo, rotating 90 degrees to open or close a cabinet door in front of television. Additionally, send request out to Insteon controller to turn off lights. Each button press from remote blinks LED, and the other LED blinks while door is opening.

All events are firing as expected and app is working well.

The one issue I’m having is with the button included in the FEZ kit. I know I have my code correct, referencing proper digital pin, but my button click event never fires. I press the button, light comes on, but even never goes. Any chance of a hardware issue or any other gotchas? I know 100% for sure it isn’t the code, I’m a professional C# developer so I am sure of it.

Thanks.


#2

Did you try connecting the button to different IO. I know you said you got C# covered but can we see a very small example on how to you have a button controlled?


#3

At this point, the code is as simple as the brochure example to isolate the issue.


public static void Main()
{
// Create Button object assigned to the a Button Component connected to Di4 with interrupt feature
FEZ_Components.Button myButton = new FEZ_Components.Button(FEZ_Pin.Interrupt.Di4);
// Assign a method to run when any event happens with the component.
myButton.ButtonPressEvent += new FEZ_Components.Button.ButtonPressEventHandler(myButton_ButtonPressEvent);
// Hold the program
Debug.Print("I have nothing to do except waiting for Button activity");
Thread.Sleep(Timeout.Infinite);
}
static void myButton_ButtonPressEvent(FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state)
{
if (state == FEZ_Components.Button.ButtonState.Pressed)
{
Debug.Print("My Button is pressed");
}
else
{
Debug.Print("My Button is not pressed");
}
}

connecting to Di4. I’ve also connected to Di13 and Di1, as well as An2, updated the code, but nothing worked.

To further isolate, I’ve run the first example, with the while loop and debug output, and that works properly, debug shows when button is in pressed state.

I’ve also swapped the connector cable for others that I know to work.

No matter what, the code never enters the method and never hits the breakpoint I have set or reports the state through debug.

As I said, other events I’ve coded (for IR reception using the SonyReceiver class) work as expected.

I think I am going to start digging into the Button driver class at this point.


#4

This is very odd. I’ve gotten it working once I started stepping through the Button Driver constructor. Even though I had specified the FEZ_Pin.Interrupt.Di4 in the code, the FEZ_Pin.Digital.Di4 constructor was still firing. I moved the line where I was instantiating “MyButton” it resolved the issue. I’ve had this happen once or twice before with vs2008 in web projects. I will update my code, compile and debug, and the old code will still be in place, like vs2008 ignores the actual update until it appears on another line. Through all of my testing and updates, I’ve never changed the line where the MyButton was instantiated.

The thing that made me think of it was when I said the while loop with the digital pin was working, but the interrupt wasn’t. So I set breakpoints in both Button constructors and saw how it was behaving.

Now that I moved the line where the MyButton was instantiated, it is working. I closed vs2008, opened it again (hadn’t closed it yet), opened my project and put back all of my removed code, and everything is working.

Sorry for wasting your time.


#5

I am not sure you are actually using interrupts. To monitor a button via interrupts, I would use an InterruptPort object.