Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

NetduinoGo Button - release event on button pressed


  • Please log in to reply
No replies to this topic

#1 Kristoffer

Kristoffer

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 25 May 2012 - 10:39 AM

Hi

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.