Having this code
using System; using System.Threading; using Microsoft.SPOT; using SecretLabs.NETMF.Hardware.NetduinoGo; namespace GoConsole { public class Program { public static void Main() { NetduinoGo.Button btn = new NetduinoGo.Button(GoSockets.Socket1); btn.ButtonPressed += new NetduinoGo.Button.ButtonEventHandler(btn_ButtonPressed); btn.ButtonReleased += new NetduinoGo.Button.ButtonEventHandler(btn_ButtonReleased); Thread.Sleep(Timeout.Infinite); } static void btn_ButtonReleased(object sender, bool buttonState) { Debug.Print(DateTime.Now.ToString("ss.fff") + " btn_ButtonReleased state: " + buttonState); } static void btn_ButtonPressed(object sender, bool buttonState) { Debug.Print(DateTime.Now.ToString("ss.fff") + " btn_ButtonPressed state: " + buttonState); } } }
If I press the button and hold it down for a short time I get this output:
33.411 btn_ButtonPressed state: True 35.495 btn_ButtonReleased state: False
Just what I expected.
If I press it and immediately release it, the output often look like this:
41.911 btn_ButtonReleased state: False 41.912 btn_ButtonPressed state: True 42.001 btn_ButtonReleased state: False
or this
13.002 btn_ButtonReleased state: False 13.003 btn_ButtonReleased state: False 13.004 btn_ButtonPressed state: True 13.116 btn_ButtonReleased state: False
Occasionally this pattern also happens if I press and hold the button down.
47.208 btn_ButtonReleased state: False 47.209 btn_ButtonPressed state: True 52.804 btn_ButtonReleased state: False
My point is, sometimes I get one or two release events before the press event even though I haven't released it, is that digital bounce and as is and should I just handle it in code then?
Thank you
Kristoffer